| name | perf-analysis |
| description | Identify performance bottlenecks — slow queries, N+1 problems, unnecessary work, memory issues, and optimization opportunities. Trigger on /perf-analysis, or when investigating slow code, high latency, or resource usage. |
| user-invocable | true |
| allowed-tools | Read, Grep, Glob, Bash |
Performance Analysis
Find and diagnose performance bottlenecks. Read-only analysis — do not optimize without verification.
Workflow
1. Identify the slow path
- What is the user-visible symptom? (slow page load, high CPU, memory growth, slow API)
- Trace the request/code path end-to-end.
- Look for obvious culprits: loops over large data, repeated DB calls, sync I/O.
2. Common anti-patterns
Database
- N+1 queries in loops.
- Missing indexes on filtered/joined columns.
- SELECT * when only a few columns are needed.
- Large result sets processed in memory.
- Slow GROUP BY / ORDER BY on unindexed columns.
Code
- Unnecessary work in hot paths (redundant computations, repeated lookups).
- Blocking I/O in async contexts.
- Large object allocations in tight loops.
- Inefficient data structures (array search instead of Set/Map).
- Recursion without depth limits.
Network
- Sequential API calls that could be parallel.
- Chatty protocols (many small requests instead of one batch).
- Large payloads with unnecessary data.
- No caching for repeated requests.
- Connection pooling issues.
Memory
- Objects retained longer than needed (closures, event listeners).
- Growing caches without eviction policy.
- Large strings/buffers held in memory.
- Stream processing vs loading everything at once.
3. Optimization rules
- Measure first — never optimize without data. Profile or instrument.
- One change at a time — change, measure, compare.
- The 80/20 rule — 80% of gains come from 20% of the code. Find that 20%.
- Know when to stop — diminishing returns. "Fast enough" is fine.
- Document the trade-off — faster code is often less readable. Note why.
Experience Log
This skill learns from experience. Mechanism:
- Read
.claude/experience/perf-analysis.md at skill start to benefit from past lessons.
- Write to
.claude/experience/perf-analysis.md after use if you learned something new.
- Format:
YYYY-MM-DD: <lesson> — one line per entry.
- Evolve: If the same issue repeats 3+ times, update this SKILL.md itself.