From rails-agent-skills
Optimizes Rails app performance: fixes N+1 queries, implements caching, profiles with Bullet/rack-mini-profiler, analyzes queries via EXPLAIN ANALYZE. Use for slow endpoints and bottlenecks.
npx claudepluginhub igmarin/rails-agent-skills --plugin rails-agent-skillsThis skill uses the workspace's default tool permissions.
Identify and fix performance bottlenecks in Rails applications.
Analyzes Rails code for performance issues like N+1 queries, missing indexes, algorithmic bottlenecks, memory usage, and scalability. Use after implementing features or addressing slowdowns.
Finds and fixes performance bottlenecks including N+1 queries, missing indexes, sync operations, and caching gaps in Node, Python, Ruby/Rails, and Go backends.
Optimizes Ruby on Rails code for performance and maintainability with 45 rules on controllers, models, ActiveRecord queries, caching, views, APIs, security, and background jobs. Use when writing, reviewing, or refactoring Rails apps.
Share bugs, ideas, or general feedback.
Identify and fix performance bottlenecks in Rails applications.
Files: SKILL.md · EXAMPLES.md · references/tools.md
NEVER optimize without a baseline measurement
ALWAYS write a regression spec before optimizing (query count assertion)
ALWAYS verify with EXPLAIN ANALYZE for database changes
REPORT ORDER MUST MATCH WORK ORDER:
1. Baseline measurement
2. Bottleneck identification (Bullet / rack-mini-profiler / EXPLAIN)
3. Regression spec written + run + FAILS at the unoptimized count
4. Fix applied
5. Regression spec rerun + PASSES at the optimized count
6. EXPLAIN ANALYZE confirms plan change
NEVER write the report as "I applied includes(:author), then wrote a spec
to lock it in." The spec MUST be written and shown failing BEFORE the fix
appears in your output. Reordering for narrative flow fails the audit even
when the underlying work was correct.
| Tool | Use |
|---|---|
bullet | N+1 detection in development |
rack-mini-profiler | Endpoint timing breakdown |
EXPLAIN ANALYZE | Query plan analysis |
See references/tools.md for detailed configuration.
# Bad
Post.all.each { |p| p.author.name }
# Good
Post.includes(:author).each { |p| p.author.name }
Write this spec before applying any optimization to lock in the expected query count:
RSpec.describe "Post index performance" do
it "loads posts with authors in a fixed number of queries" do
create_list(:post, 10, :with_author)
expect do
Post.includes(:author).to_a
end.to make_database_queries(count: 2) # posts + authors
end
end
Use the db-query-matchers gem or a custom make_database_queries matcher. The spec must pass after the fix and fail if a future change reintroduces the N+1.
Run directly in rails dbconsole (PostgreSQL) after applying an index or query change:
EXPLAIN ANALYZE
SELECT posts.*, users.name
FROM posts
INNER JOIN users ON users.id = posts.author_id
WHERE posts.published = true;
Key things to check in the output:
Seq Scan on large tables → should become Index Scan after adding an indexactual time rows — confirm the new value is lower than the baselinerows estimate accuracy — large discrepancies indicate stale statistics (ANALYZE table_name)See EXAMPLES.md for complete examples including:
includes, preload, joinspluck and find_eachReport sections, in the HARD-GATE order:
bullet, rack-mini-profiler, or EXPLAIN ANALYZE — at least one named).make_database_queries(count: <unoptimized>), shown failing.Seq Scan → Index Scan or actual time delta.queries: N → M, p95: X ms → Y ms. Numbers, not adjectives.