Rails N+1 query detection with Bullet

11058
0

N+1 queries are the most common Rails performance problem—loading associations in loops causes exponential database queries. The Bullet gem detects N+1s in development and suggests fixes. It monitors queries and alerts when you should use includes, preload, or eager_load. I configure it to show notifications in the browser console and raise errors in tests. The gem also catches unused eager loading, where you preload associations but never access them. Fixing N+1s typically involves adding includes(:association) to queries. For complex nested associations, I use strict_loading mode to catch issues early. Bullet is essential tooling—it finds issues CI can't catch.