Performance: Eager loading (N+1 prevention)
HIGH IMPACT
This concept affects database query efficiency and page load speed by reducing the number of queries needed to fetch related data.
posts = Post.includes(:author).all posts.each do |post| puts post.author.name end
posts = Post.all posts.each do |post| puts post.author.name end
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| N+1 queries (lazy loading) | Normal | Multiple due to delayed data | Higher due to slower data | [X] Bad |
| Eager loading with includes | Normal | Single or fewer | Lower due to faster data | [OK] Good |