John Kevin Basco Sun Aug 26 20:18:23 -0400 2012

Subject: Eager loading vs Lazy loading

Which is really faster?? To LAZY LOAD or to EAGER LOAD many associations w/ large data sets??? Because based on my research eager loading is faster because it queries all the data at once or minimizes the number of queries to be executed. But based on my experience why is lazy loading faster? Here is the scenario: users table have many posts and each posts has many comments and each comment has many author.

I dump many data in the tables in the database:
47 total rows in the users table
1305 total rows in the posts table
1138 total rows in the comments table
788 total rows in the authors table

Here is the benchmark:


Loading Time: Base Classes 0.0216
Controller Execution Time ( Welcome / Eager ) 16.1154
Total Execution Time 16.1371

Loading Time: Base Classes 0.0120
Controller Execution Time ( Welcome / Lazy ) 4.0325
Total Execution Time 4.0446