performance-optimization

Detect and resolve N+1 queries and slow database queries in Rails applications.

Updated Feb 8, 2026
One-click install
npx skills add https://github.com/mlbright/notes --skill performance-optimization-mlbright
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: performance-optimization
Source: https://github.com/mlbright/notes/tree/main/.github/skills/performance-optimization
Command: npx skills add https://github.com/mlbright/notes --skill performance-optimization-mlbright

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires bullet, rack-mini-profiler, memory_profiler, stackprof, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses performance bottlenecks in Rails applications, ensuring faster response times and a smoother user experience by optimizing database queries and memory usage.

Core Features & Use Cases

  • N+1 Query Detection & Prevention: Identifies and resolves inefficient database query patterns.
  • Query Optimization: Provides strategies for writing faster, more efficient SQL queries.
  • Memory Management: Offers techniques to reduce application memory footprint.
  • Use Case: A user reports that their application's dashboard is loading slowly. This Skill can be used to analyze the underlying database queries and identify N+1 problems or slow queries that need optimization.

Quick Start

Use the performance-optimization skill to analyze and fix N+1 queries in the application's event listing.

Frequently Asked Questions about performance-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix N+1 queries in a Rails application?

To resolve N+1 queries in Rails, you identify inefficient database query patterns and apply eager loading strategies. This optimization prevents excessive database calls by batching related data retrieval into fewer, faster SQL queries for smoother performance.

What is the best way to profile slow database queries in Rails?

Profiling slow database queries in Rails is best achieved using the rack-mini-profiler gem to monitor request response times. This approach pinpoints specific SQL bottlenecks within your development environment for targeted query optimization.

How does the Bullet gem work for detecting Rails query inefficiencies?

The Bullet gem works by monitoring your Rails application's object-relational mapping to detect N+1 queries and unused eager loading. It alerts you during development and testing when database queries can be optimized for better performance.

How do I reduce memory usage in a Rails application?

Reducing memory usage in Rails involves analyzing your application's memory footprint with the memory_profiler gem. This process identifies memory leaks and inefficient object allocations, enabling techniques to streamline memory consumption and improve speed.

Can I use stackprof to optimize Rails memory and performance?

Yes, you can use stackprof to sample and profile your Rails application's stack to identify expensive method calls. This sampling profiler highlights exact code paths consuming high memory and CPU, guiding targeted performance optimizations.

Do I need to configure my Rails environment to use performance monitoring tools?

Yes, using performance monitoring tools requires configuring your Rails development and test environments. This setup enables profiling dependencies like rack-mini-profiler and Bullet to actively track and report database queries and memory inefficiencies.