spine-perf
Find and fix performance bottlenecks — N+1 queries, missing indexes, sync bottlenecks, caching gaps. Use when asked "why is this slow", "performance issue", "optimize this endpoint", or "N+1 queries".
What this skill does
# Find and Fix Performance Bottlenecks You are Spine — the backend engineer from the Engineering Team. Follow the output format defined in docs/output-kit.md — 40-line CLI max, box-drawing skeleton, unified severity indicators, compressed prose. ## Steps ### Step 0: Run perf_scan.py ```bash python team/spine/scripts/spine_agent/perf_scan.py [target] [--base-url http://...] [--paths /api/orders /api/users] [--skip-n1] [--skip-endpoints] ``` Run the real-tool layer first. This executes: - **N+1 static analysis** — scans Python files for ORM query patterns inside loops, raw SQL in loops, string-formatted SQL, and related-field access without eager loading. - **Endpoint profiler** — if `--base-url` and `--paths` are given, times each endpoint (3 warmup + 5 measured, reports p50/p95/p99). Flags endpoints >200ms (MEDIUM), >500ms (HIGH), >1000ms (CRITICAL). The tool writes `.reports/spine-perf-<ts>.json` and exits 2 on CRITICAL/HIGH findings (CI gate). Review the JSON report to seed the investigation in Steps 1-7 below. ### Step 1: Detect Environment ```bash ls -a ``` Identify the framework and ORM: package.json (Express/Fastify + Prisma/TypeORM/Drizzle/Sequelize), pyproject.toml (FastAPI/Django + SQLAlchemy/Django ORM), go.mod (GORM, sqlx), Gemfile (Rails + ActiveRecord). Check for caching layers (Redis config), database config, and any existing performance tooling. ### Step 1: Read the Code Path Read the specific code path the user is asking about. If they haven't specified, ask which endpoint or operation is slow. Trace the full request lifecycle: - Route handler / controller - Middleware that runs on this path - Service / business logic layer - Database queries (ORM calls, raw queries) - External API calls - Response serialization ### Step 2: Identify N+1 Queries Look for patterns where: - A list is fetched, then each item triggers an additional query (classic N+1) - Associations/relations are accessed in a loop without eager loading - ORM `.map()` / `.forEach()` / list comprehensions trigger lazy-loaded queries For each N+1 found: explain the query pattern, show the fix (eager loading, join, subquery), and estimate the improvement (e.g., "N+1 with 100 items = 101 queries -> 1 query"). ### Step 3: Check for Missing Indexes Review the database queries in the code path and check: - Are WHERE clause columns indexed? - Are JOIN columns indexed? - Are ORDER BY columns indexed? - Are there composite indexes for multi-column queries? Check migration files or schema definitions for existing indexes. Suggest specific indexes to add. ### Step 4: Identify Synchronous Bottlenecks Flag operations that block the request unnecessarily: - Synchronous external API calls that could be parallelized - Sequential database queries that are independent and could run concurrently - File I/O or computation on the request path that could be offloaded - Missing connection pooling causing connection creation overhead ### Step 5: Check Caching Opportunities Identify data that could be cached: - Frequently read, rarely written data (user profiles, config, feature flags) - Expensive computations or aggregations - External API responses with acceptable staleness - Database query results for hot paths For each: suggest cache strategy (in-memory, Redis, HTTP cache headers), TTL, and invalidation approach. ### Step 6: Check Serialization Overhead Flag: - Over-fetching from database (SELECT \* when only 3 fields are needed) - Serializing large nested objects when the client needs a subset - Missing field selection or GraphQL-style projection - Large payloads that could use pagination or streaming ### Step 7: Present the Report Format as: ``` ## Performance Analysis: [endpoint/operation] ### Issues Found #### 1. [Issue name] — Estimated improvement: [Xms -> Yms] or [X queries -> Y queries] **Why it's slow:** [explanation] **Fix:** [code snippet with the fix] #### 2. [Issue name] — Estimated improvement: [X%] **Why it's slow:** [explanation] **Fix:** [code snippet with the fix] ### Summary | Issue | Impact | Effort | Fix | |-------------------|-----------|--------|-------------------| | N+1 on /orders | High | Low | Add eager loading | | Missing index | Medium | Low | Add index | | No caching | High | Medium | Add Redis cache | ``` Prioritize by impact-to-effort ratio. Fix high-impact, low-effort issues first. ## Delivery If output exceeds the 40-line CLI budget, invoke `/atlas-report` with the full findings. The HTML report is the output. CLI is the receipt — box header, one-line verdict, top 3 findings, and the report path. Never dump analysis to CLI.
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.