performance-optimization_skill

This skill helps optimize Rails performance by detecting N+1 queries, indexing gaps, and memory issues to speed up responses.

269

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill thibautbaissac/rails_ai_agents --skill performance-optimization

  • SKILL.md10.4 KB

Overview

This skill identifies and fixes common Rails performance problems such as N+1 queries, slow SQL, and memory bloat. It provides practical fixes: eager loading patterns, indexing guidance, batching, and profiling integration with tools like Bullet and rack-mini-profiler. Use it to improve response times, reduce DB load, and lower memory usage in Rails 8 applications.

How this skill works

The skill inspects controller actions, ActiveRecord usage, and test suites to detect inefficient patterns (N+1, unnecessary selects, full-table loads). It suggests concrete code changes: includes/preload/eager_load, counter_cache migrations, selective select/pluck, batch processing, and appropriate indexes. It also recommends configuration and test hooks for Bullet, rack-mini-profiler, and memory_profiler and helps interpret EXPLAIN output and slow-query logging.

When to use it

  • When pages or endpoints are slow or response times regress
  • When tests or Bullet report N+1 queries
  • When memory usage or GC spikes in console or production
  • When database queries are unexpectedly high or slow
  • Before deployment to ensure no critical N+1s or missing indexes

Best practices

  • Enable Bullet in development and raise in test to catch N+1 early
  • Prefer includes and scoped eager loading; use eager_load when filtering on associations
  • Use counter_cache for frequent counts and exists? for presence checks
  • Select only needed columns or use pluck to avoid AR object overhead
  • Process large datasets with find_each or in_batches and prefer update_all for mass updates
  • Add indexes for foreign keys, WHERE, ORDER BY, and common JOIN columns

Example use cases

  • Fixing an N+1 caused by rendering a list of events with associated venues
  • Reducing page load by replacing Event.all.each with Event.find_each and pluck
  • Adding a composite index to speed a filtered, paginated query
  • Adding Bullet to CI/test so requests fail on N+1 regressions
  • Using rack-mini-profiler and flamegraphs to locate slow controller code paths

FAQ

Use preload to force separate queries when datasets are large; use eager_load (LEFT JOIN) when you need to filter or sort on the association.

How do I detect missing indexes quickly?

Scan tables for *_id columns without indexes programmatically or review slow queries and EXPLAIN output; add single or composite indexes where WHERE, JOIN, or ORDER BY are frequent.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
performance-optimization skill by thibautbaissac/rails_ai_agents | VeilStrat