Comparison
Lazy initialisationvsVirtual proxy
Lazy initialisation
the field is null until the first person asks for it, and the first person asking pays for it.
Deferring the creation of something until it is first needed, so startup is cheap and unused things are never built. It moves cost from a predictable moment to an unpredictable one, which is fine for a cache and painful for a database connection opened during the first user request. Under concurrency it stops being a one-liner, which is what double-checked locking is about.
Full entry →Virtual proxy
you had an object with an id and nothing else, and touching any other property fired a query.
A proxy that stands in for an expensive object and creates or loads it on first real use. It is the mechanism behind ORM lazy loading and behind placeholder objects in graphics and document systems. Its characteristic problem is that the cost is invisible at the call site, which is precisely how the N+1 query gets written by someone who thought they were reading a field.
Full entry →