Faster Rails: Eliminating N+1 queries

Rails does not scale well – this argument is often used to downplay the worth of the language and the framework. Yet, many businesses from small startups to platforms with millions of users use it as the backbone of their operations. A good question to ask ourselves is whether Rails simply can’t scale, or if the issue is hidden somewhere deeper.

Imported from Disqus

-

Avatar

Yug Shende3 years ago

Is this the case even with latest builds of Rails 5? I think I read/heard a specific Rails community person say the’re trying to do away with N+1. Or I am guessing .includes(:branches) IS the solution that they’ve baked in.

Igor Sarcevic Yug Shende3 years ago

Good question. We’ll need to look into the latest Rails 5.x release.

But my best guess is that this is not possible to resolve completely. Using includes every time has the opposite risk of loading too much data.

Bibin Venugopal Igor Sarcevic2 years ago

True loading too much data will end up more RAM consumption.

Plus how do they do a eager loading in first query? How do they know that the data going to end up in a N+1 situation in later code?