AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Performance Optimization

skill-thibautbaissac-rails-ai-agents-performance-optimization · by ThibautBaissac

>-

No reviews yet
0 installs
24 views
0.0% view→install

Install

$ agentstack add skill-thibautbaissac-rails-ai-agents-performance-optimization

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-thibautbaissac-rails-ai-agents-performance-optimization)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
3mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Performance Optimization? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Performance Optimization for Rails 8

Overview

Performance optimization focuses on:

  • N+1 query detection and prevention
  • Query optimization
  • Memory management
  • Response time improvements
  • Database indexing

Quick Start

# Gemfile
group :development, :test do
  gem 'bullet'           # N+1 detection
  gem 'rack-mini-profiler' # Request profiling
  gem 'memory_profiler'  # Memory analysis
end

N+1 Query Detection and Prevention

N+1 queries occur when code loads a collection then makes a separate query for each associated record. The Bullet gem detects these automatically. Fix them with eager loading via includes, preload, or eager_load.

Eager Loading Decision Table

| Method | Use When | |--------|----------| | includes | Most cases (Rails chooses best strategy) | | preload | Forcing separate queries, large datasets | | eager_load | Filtering on association, need single query | | joins | Only need to filter, don't need association data |

Key patterns: Bullet configuration, eager loading methods, scoped eager loading, counter caches, N+1 specs with query count assertions.

See [references/n-plus-one.md](references/n-plus-one.md) for all code examples and patterns.

Query Optimization

Optimize queries by selecting only needed columns, using batch processing for large datasets, and choosing efficient existence checks.

Key Patterns

| Pattern | Bad | Good | |---------|-----|------| | Column selection | User.all.map(&:name) | User.pluck(:name) | | Large iterations | Event.all.each { ... } | Event.find_each { ... } | | Existence checks | .any? / .present? | .exists? | | Collection size | .length (loads all) | .size (smart) |

Database Indexing

Add indexes for: foreign keys, columns in WHERE/ORDER BY/JOIN clauses, and unique constraints. Use composite indexes for multi-column queries. Use partial indexes for filtered subsets.

Query Analysis

Use Event.where(...).explain(:analyze) to inspect query plans. Set up slow query logging via ActiveSupport::Notifications to catch queries over a threshold.

See [references/query-optimization.md](references/query-optimization.md) for all code examples and patterns.

Memory Management and Profiling

Use memory_profiler to detect memory issues. Prefer pluck over loading full AR objects, use find_each for streaming, and use update_all / in_batches for bulk operations.

Rack Mini Profiler

Provides per-request profiling in development. Shows query count, timing, and flamegraphs (with stackprof gem). Access via the profiler badge or ?pp=flamegraph.

See [references/memory-and-profiling.md](references/memory-and-profiling.md) for all code examples and patterns.

Quick Fixes Reference

| Problem | Solution | |---------|----------| | N+1 on belongsto | includes(:association) | | N+1 on hasmany | includes(:association) | | Slow COUNT | Add counter_cache | | Loading all columns | Use select or pluck | | Large dataset iteration | Use find_each | | Missing index on FK | Add index on *_id columns | | Slow WHERE clause | Add index on filtered column | | Loading unused associations | Remove from includes |

Performance Checklist

  • [ ] Bullet enabled in development/test
  • [ ] No N+1 queries in critical paths
  • [ ] Foreign keys have indexes
  • [ ] Counter caches for frequent counts
  • [ ] Eager loading in controllers
  • [ ] Batch processing for large datasets
  • [ ] Query analysis for slow endpoints

Workflow

  1. Detect -- Enable Bullet, run specs, check Rack Mini Profiler
  2. Analyze -- Use explain(:analyze), check slow query logs, profile memory
  3. Fix -- Apply the appropriate pattern from the reference files
  4. Verify -- Re-run specs, confirm query counts, check profiler

Reference Files

  • [references/n-plus-one.md](references/n-plus-one.md) -- N+1 detection, eager loading methods, Bullet config, counter caches, testing patterns
  • [references/query-optimization.md](references/query-optimization.md) -- Column selection, batch processing, indexing strategies, EXPLAIN analysis, slow query logging
  • [references/memory-and-profiling.md](references/memory-and-profiling.md) -- Memory profiler usage, memory-efficient patterns, Rack Mini Profiler setup, deployment checklist

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.