| name | performance_profiling |
| description | Identifies performance bottlenecks and optimization opportunities in code. Invoke when addressing slow operations, high resource usage, or preparing for scale. |
SKILL: Performance Bottleneck Analysis
🎯 Objective
Systematically identify and quantify performance issues. Provide actionable optimization recommendations with measurable impact estimates.
🧠 Core Principle: Measure First, Optimize Second
Never optimize based on assumptions. Profile actual execution to find real bottlenecks. Focus optimization effort on the 20% of code causing 80% of latency.
📊 Impact Legend
CRITICAL — Dominant cost (largest share of latency/memory) or a hard scaling ceiling. Fix first.
HIGH — Significant, measured cost worth fixing this cycle.
MEDIUM — Real but secondary cost.
LOW — Minor or speculative; note and defer.
✅ Verification Discipline
Every finding must cite a measurement, not a hunch. "This loop looks slow" is not a finding; "this loop is 62% of request time (profiler, n=1k)" is. State the tool, the workload, and the number. If you could not measure, label the item explicitly as a hypothesis to validate, not a confirmed bottleneck.
Tooling by ecosystem: Node --prof / clinic.js / 0x; Python cProfile / py-spy; JVM async-profiler / JFR; Go pprof; browser DevTools Performance panel; DB EXPLAIN ANALYZE.
🛠️ Execution Pipeline
1. BASELINE_MEASUREMENT
Goal: Quantify "now" before changing anything.
How to verify: Capture percentiles (p50/p95/p99), not just averages — averages hide tail latency that users actually feel.
2. HOT_PATH_IDENTIFICATION
Goal: Find where the time actually goes.
3. ALGORITHM_ANALYSIS
Goal: Fix complexity, not just constants.
Example:
const dups = a.filter(x => b.includes(x));
const set = new Set(b);
const dups = a.filter(x => set.has(x));
4. I/O_ANALYSIS
Goal: Stop waiting on the network and disk.
Example:
for (const id of ids) results.push(await fetch(id));
const results = await Promise.all(ids.map(fetch));
5. MEMORY_ANALYSIS
Goal: Find leaks and allocation churn.
6. CONCURRENCY_REVIEW
Goal: Use the cores without breaking correctness.
7. DATABASE_PERFORMANCE
Goal: Make the database do less work.
How to verify: Run EXPLAIN ANALYZE on slow queries. A Seq Scan over a large table on a filtered column usually means a missing index.
8. CACHING_ANALYSIS
Goal: Reuse work safely.
9. NETWORK_OPTIMIZATION
Goal: Move fewer bytes, fewer times.
10. SCALABILITY_ASSESSMENT
Goal: Confirm it holds under growth.
📤 Output Directives
Report format: [IMPACT] Location: current cost → projected cost. Technique. (measurement source)
Example output:
[CRITICAL] getDashboard(): 1,200ms p95, 90% in N+1 order lookup (450 queries). Batch to 1 query → ~120ms. (clinic.js)
[HIGH] search(): O(n²) dedupe over ~5k items, 380ms. Use Set → ~15ms. (cProfile)
[MEDIUM] /assets/*: no gzip, 2.1MB transfer. Enable brotli → ~400KB. (DevTools)
[LOW] config parse on each request, ~3ms. Cache at startup. (manual timing)