Performance profiling with rack-mini-profiler and tools

Sarah Mitchell Feb 2026
2 tabs
# Gemfile
group :development do
  gem 'rack-mini-profiler'
  gem 'memory_profiler'
  gem 'stackprof'  # For flamegraphs
  gem 'bullet'     # N+1 detection
end

# config/initializers/rack_profiler.rb
if Rails.env.development?
  require 'rack-mini-profiler'

  # Memory profiling
  Rack::MiniProfiler.config.enable_advanced_debugging_tools = true

  # Store results in memory
  Rack::MiniProfiler.config.storage = Rack::MiniProfiler::MemoryStore

  # Position of profiler badge
  Rack::MiniProfiler.config.position = 'bottom-right'

  # Skip profiling for certain paths
  Rack::MiniProfiler.config.skip_paths = ['/assets', '/packs']
end

# config/initializers/bullet.rb
if Rails.env.development?
  Bullet.enable = true
  Bullet.bullet_logger = true
  Bullet.console = true
  Bullet.add_footer = true

  # Detect N+1 queries
  Bullet.alert = true

  # Detect unused eager loading
  Bullet.unused_eager_loading_enable = true

  # Detect counter cache misses
  Bullet.counter_cache_enable = true
end

# Usage in code - manual profiling blocks
def index
  Rack::MiniProfiler.step("Loading users") do
    @users = User.includes(:posts).page(params[:page])
  end

  Rack::MiniProfiler.step("Loading categories") do
    @categories = Category.all
  end
end

# Memory profiling in console
require 'memory_profiler'

report = MemoryProfiler.report do
  10_000.times { User.new(name: 'Test', email: 'test@example.com') }
end

report.pretty_print

# Flamegraph profiling
# Visit: http://localhost:3000/posts?pp=flamegraph
# Generates interactive flamegraph showing method call hierarchy
2 files · ruby Explain with highlit

rack-mini-profiler reveals performance bottlenecks in Rails apps. It displays database queries, rendering time, memory allocation on every page. I use Flamegraphs to visualize where time is spent. Memory profiling identifies allocation hotspots. Query analysis shows N+1 queries, slow queries. Profiling in development catches issues before production. ?pp=flamegraph generates interactive flame graphs. Database query backtraces show exactly which code triggered queries. rack-mini-profiler integrates with bullet for N+1 detection. Understanding profiling output guides optimization—focus on highest impact areas. Production profiling uses tools like New Relic, Skylight. Profiling transforms guessing into data-driven optimization.