long id

Oct. 1st, 2015 02:02 pm
juan_gandhi: (VP)
[personal profile] juan_gandhi
I think I got it where all this bs about passing around numerical ids of entities instead of entity references (maybe lazy) come from. It's like 'error code'. It comes from the ancient c programming, where we just could not allocate a string for a readable piece of text, or for the data that may need some efforts to instantiate or allocate.

In short. It's stupid to pass around "ids" in a program.

Date: 2015-10-02 03:59 am (UTC)
From: [identity profile] yatur.livejournal.com
I think C programming has nothing (or little) to do with it. Access to (relational) databases via lazy objects references is very harmful to performance.

Databases are designed to get mass quantities of records in one shot. E.g. retrieving 10,000 records via some simple query (SELECT * FROM Users WHERE OrganizationId=125) is virtually instantaneous. Lazy entity references are designed to get one object at a time. Retrieving 10,000 records via 10,000 queries (SELECT * FROM Users WHERE UserId=n x10,000 times) will take forever.

ORMs like Hibernate do provide lazy references, and make things look easy on toy databases. However, this ease is deceiving. Later on you find yourself rewriting half of the program getting rid of the lazy references, because it just does not work fast enough in production.
Edited Date: 2015-10-02 04:03 am (UTC)

Date: 2015-10-02 06:27 am (UTC)
From: [identity profile] sleepy-drago.livejournal.com
You saying it like ppl dont know about "Later on...". Pro know exactly when to cash their stock and move on from a startup to greener pastures.

C programmers have other sins. Often they mix numbers that are identifiers for different things. I once coined for myself a label after working some legacy codebase: "program composed from integers". If highest abstraction in a code you have to ship is integer you know you're screwed.
Edited Date: 2015-10-02 06:29 am (UTC)

Date: 2015-10-02 10:03 am (UTC)
From: [identity profile] metaclass.livejournal.com
If we have sufficiently strong type system and adequate language we can represent lazy reference as eight byte long id (and still has 2-3 lower bits for some flags, due to alignment).
But what we have are layers and layers of performance-killing wrappers like in (N)Hibernate and it`s much easier to work with simple types (long,int,whatever) in record fields.

Also these wrappers are not actually transparent. Simple long id cannot cause a LazyInitializationException, unlike some wrapper with reference to long-closed Session.

Date: 2015-10-02 02:42 pm (UTC)
From: [identity profile] juan-gandhi.livejournal.com
Weird idea to issue 10k queries for retrieving 10k records.

Date: 2015-10-02 02:56 pm (UTC)
From: [identity profile] yatur.livejournal.com
> Weird idea to issue 10k queries for retrieving 10k records.

Would do you mean "weird idea"? That's how lazy references work. Be careful what you are wishing for :)


var auditRecords = myLog.GetAudit(); // gets 10K audit records

foreach (var record in auditRecords) // loops 10K times
{
var user = record.User; // a lazy reference
if (user.IsAdmin) ... // causes "user" to be instantiated from DB via query
}



Date: 2015-10-02 03:07 pm (UTC)
From: [identity profile] juan-gandhi.livejournal.com
Right. It is an interesting problem. Not that a hard-coded ad-hoc solution is an answer.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

June 2025

S M T W T F S
1 2345 6 7
8 9 10 11 121314
15161718 1920 21
222324252627 28
29 30     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 6th, 2025 12:52 am
Powered by Dreamwidth Studios