What is Lazy Loading?
[Edit after reading a few answers] Why do people use this term so often?
Say you just use a ASP/ADO recordset and load it with data or
is a Design pattern.
Lazy loading: Untill your code require some operation done by a particular object, object is not initilaized, and once it's initialized it doesn't re-initialize the object but uses the previously initialized object.
This makes your code much more efficient and helps managing memory usage.
Example Applications of Lazy loading:
Ghost Lazy initialization Value holder
It's called lazy loading because, like a lazy person, you are putting off doing something you don't want to. The opposite is Eager Loading, where you load something right away, long before you need it.
If you are curious why people might use lazy loading, consider an application that takes a LOOOOONG time to start. This application is probably doing a lot of eager loading... loading things from disk, and doing calculations and whatnot long before it is ever needed.
Compare this to lazy loading, the application would start much faster, but then the first time you need to do something that requires some long running load, there may be a slight pause while it is loaded for the first time. Thus, with lazy loading, you are amortizing the load time throughout the course of running your application... and you may actually save from loading things that the user may never intend to use.
Some of the advantages of lazy loading:
Here's an example from some actual Python code I wrote:
class Item(Model):
...
@property
def total(self):
if not hasattr(self, "_total"):
self._total = self.quantity \
+ sum(bi.quantity for bi in self.borroweditem_set.all())
return self._total
Basically, I have an Item class which represents an item in our inventory. The total number of items we have is the number that we own plus the sum of all of the items that we're borrowing from various sources. These numbers are all stored in our database, and it would be pointless to calculate this until the total is actually requested (since often Items will be used without the total being requested).
So the total property checks whether the _total field exists. If it doesn't, then the property code queries the database and computes it, then stores the value in the _total field so that it need not be recomputed the next time it's requested.
Lazy loading is a concept where we delay the loading of the object unit the point where we need it. Putting in simple words on demand object loading rather than loading the objects unnecessarily. For instance if you have a "Customer" class which has "Orders" object aggregated. So you like to load the customer data but the orders objects you would like to delay until your application needs it.
Below is a youtube video which demonstrates how to use lazy loading , how we can implement lazy loading and advantages and disadvantages of the same.
http://www.youtube.com/watch?v=2SrfdAkwmFo
Lazy loading is a term frequently used in databases to refer to the concept of loading parts of the required info only when it's needed.
I.e. suppose you needed to have a record which has a join of several tables. If you fetched it all at once it would take longer than if you would fetch say only the main table. Using lazy-loading the rest of the information will be fetched only if it is needed. So it is actually 'efficient-loading' in certain scenarios.
The other types of 'loading' is: