---
title: "Speed Up Your Rails App by Squashing N+1 Queries"
url: https://daily.dev/posts/speed-up-your-rails-app-by-squashing-n-1-queries-ptt97gwbo
source_url: https://hashrocket.com/blog/posts/speed-up-your-rails-app-by-squashing-n-1-queries
type: article
source: "Hashrocket"
published: 2025-11-20T14:40:10.146Z
updated: 2025-11-20T14:40:30.105Z
tags: ["performance", "database", "ruby", "rails"]
reading_time: 6
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Speed Up Your Rails App by Squashing N+1 Queries

**[Hashrocket](https://daily.dev/sources/hashrocket)** · 6 min read · 0 upvotes · 0 comments

## Summary

N+1 queries occur when iterating over ActiveRecord models while accessing associated records, causing exponential database queries. Using Rails' .includes method to eagerly load associations can dramatically reduce query count—from 1,101 queries down to just 3 in a real example. This optimization technique reduced page load time by 87%, from 1.007s to 0.126s, by bulk-loading related records upfront instead of querying them individually.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://hashrocket.com/blog/posts/speed-up-your-rails-app-by-squashing-n-1-queries>

## Similar posts on daily.dev

- [How to Fix N\+1 Queries in Rails Like a Pro](https://daily.dev/posts/how-to-fix-n-1-queries-in-rails-like-a-pro-bdttomg9q) · Ruby Flow · 1 upvotes · 0 comments
- [The N\+1 Query Problem in Active Record](https://daily.dev/posts/the-n-1-query-problem-in-active-record-yh0vscveu) · Ruby Flow · 0 upvotes · 0 comments
- [Why N\+1 Queries Are a Natural Result of Lazy Loading](https://daily.dev/posts/why-n-1-queries-are-a-natural-result-of-lazy-loading-b9boclvq7) · Ruby Flow · 1 upvotes · 0 comments
- [Rails Performance: 5 Critical Bottlenecks You're Missing](https://daily.dev/posts/rails-performance-5-critical-bottlenecks-you-re-missing-5oqvvhlb9) · Ruby Flow · 0 upvotes · 0 comments

---

Tags: [#performance](https://daily.dev/tags/performance), [#database](https://daily.dev/tags/database), [#ruby](https://daily.dev/tags/ruby), [#rails](https://daily.dev/tags/rails)

[View this post on daily.dev](https://daily.dev/posts/speed-up-your-rails-app-by-squashing-n-1-queries-ptt97gwbo)
