Eager Loading for ActiveRecord Performance
summary
Explains how ActiveRecord turns an N+1 into fewer queries using includes -> 2 queries and how includes chooses between the two-query preload strategy and a slower LEFT OUTER JOIN eager_load; shows preload and eager_load APIs and when to force them. Demonstrates counter_cache cutting many queries to 1 query by storing counts (migration + backfill required) and shows Russian-doll fragment caching combined with fast_jsonapi and Bullet to eliminate DB reads for warm caches; demo with 10 posts × 1,000 comments (10,000 records) validates the approach.
AI-written summary · about
chapters (7)
- 0:00Start
- 9:33Chaining
- 11:13Relations execute queries lazily
- 16:02#preload
- 28:44on a cold cache
- 32:35the power of lazy
- 34:16THE NETFLIX TECH BLOG
related talks
33mExperimental Patterns in ActiveRecord
10mHigh Perfmance Caching with Rails
38mSequel: When ActiveRecord is not enough
01h 15mSpeedupRails, Speedup Your Code
36mCache is King
40mTricks That Rails Didn't Tell You About
46mUse PostgreSQL, not Rails, to make Rails Faster!
37mCache is King: Get the Most Bang for Your Buck From Ruby
