Performance Skill
Core Philosophy
"Measure first; optimize where it matters."
Find real bottlenecks with profiling or benchmarks, then improve. Avoid premature or speculative optimization.
Protocol
1. Measure
- Profile: Use language/runtime profilers (e.g. Node:
--inspect / Chrome DevTools; Python: cProfile, py-spy; Go: pprof; Rust: cargo flamegraph).
- Benchmark: Add or run benchmarks for the hot path (e.g.
benchmark.js, pytest-benchmark, go test -bench, cargo bench).
- Baseline: Record current metrics (time, memory, throughput) so improvements are verifiable.
2. Identify Bottlenecks
- Hot spots: Where the profiler shows most time or allocations.
- N+1 / redundant work: Repeated queries, duplicate computation, unnecessary allocations.
- Algorithm/design: Wrong data structure, O(n²) where O(n) is possible, blocking I/O on hot path.
- I/O: Disk, network, or DB; consider caching, batching, or async.
Focus on the top one or two bottlenecks; avoid scattering small optimizations.
3. Optimize
- Algorithm/data structure: Fix the dominant cost first.
- Caching: Add only where there’s measurable gain and clear invalidation.
- I/O: Batch, pool, async, or reduce round-trips.
- Allocations: Reduce in hot loops (reuse, pool, or avoid unnecessary copies) when the profiler shows pressure.
Preserve correctness and readability; add a short comment or test for non-obvious optimizations.
4. Verify
- Re-run profile or benchmarks; confirm improvement and no regression elsewhere.
- Run the full test suite.
5. Observability & Instrumentation
Add observability to understand production behavior and diagnose performance issues. Use structured logging, metrics (RED method), and tracing for distributed systems.
For complete instrumentation guidance: See reference/INSTRUMENTATION.md, which covers:
- Performance-specific observability (logging, metrics, tracing)
- Instrumentation by ecosystem (Node, Python, Go, Rust)
- Profiling commands by ecosystem
- MCP Integration (Datadog) for performance diagnosis
- Best practices (log slow operations, instrument hot paths, track RED metrics)
Checklist
Cross-Skill Integration
| Situation |
Skill to invoke |
How |
| Performance issue in production |
Datadog MCP |
Use query_metrics, search_logs, query_traces (after /setup) |
| Optimization changes need review |
code-reviewer skill |
Read skills/code-reviewer/SKILL.md |
| Optimization reveals security concern |
security-reviewer skill |
Read skills/security-reviewer/SKILL.md |
| Need benchmarks in CI |
ci-cd skill |
Read skills/ci-cd/SKILL.md |
| Logging/tracing needs tests |
testing skill |
Read skills/testing/SKILL.md |
1---2name: performance3description: Analyze and improve performance: profile, find bottlenecks, optimize, and instrument code with observability for diagnosing performance issues (profiling, bottleneck tracing). Use when the user asks about performance, slow code, bottlenecks, profiling, optimization, or adding performance-specific observability.4---56# Performance Skill78## Core Philosophy910**"Measure first; optimize where it matters."**1112Find real bottlenecks with profiling or benchmarks, then improve. Avoid premature or speculative optimization.1314---1516## Protocol1718### 1. Measure1920- **Profile**: Use language/runtime profilers (e.g. Node: `--inspect` / Chrome DevTools; Python: `cProfile`, `py-spy`; Go: `pprof`; Rust: `cargo flamegraph`).21- **Benchmark**: Add or run benchmarks for the hot path (e.g. `benchmark.js`, `pytest-benchmark`, `go test -bench`, `cargo bench`).22- **Baseline**: Record current metrics (time, memory, throughput) so improvements are verifiable.2324### 2. Identify Bottlenecks2526- **Hot spots**: Where the profiler shows most time or allocations.27- **N+1 / redundant work**: Repeated queries, duplicate computation, unnecessary allocations.28- **Algorithm/design**: Wrong data structure, O(n²) where O(n) is possible, blocking I/O on hot path.29- **I/O**: Disk, network, or DB; consider caching, batching, or async.3031Focus on the top one or two bottlenecks; avoid scattering small optimizations.3233### 3. Optimize3435- **Algorithm/data structure**: Fix the dominant cost first.36- **Caching**: Add only where there’s measurable gain and clear invalidation.37- **I/O**: Batch, pool, async, or reduce round-trips.38- **Allocations**: Reduce in hot loops (reuse, pool, or avoid unnecessary copies) when the profiler shows pressure.3940Preserve correctness and readability; add a short comment or test for non-obvious optimizations.4142### 4. Verify4344- Re-run profile or benchmarks; confirm improvement and no regression elsewhere.45- Run the full test suite.4647### 5. Observability & Instrumentation4849Add observability to understand production behavior and diagnose performance issues. Use structured logging, metrics (RED method), and tracing for distributed systems.5051**For complete instrumentation guidance:** See [reference/INSTRUMENTATION.md](reference/INSTRUMENTATION.md), which covers:52- Performance-specific observability (logging, metrics, tracing)53- Instrumentation by ecosystem (Node, Python, Go, Rust)54- Profiling commands by ecosystem55- MCP Integration (Datadog) for performance diagnosis56- Best practices (log slow operations, instrument hot paths, track RED metrics)5758---5960## Checklist6162- [ ] Bottleneck identified with data (profile or benchmark), not guess.63- [ ] Change targets the hot path or dominant cost.64- [ ] Improvement measured; tests still pass.65- [ ] Trade-offs (e.g. readability, memory) noted when relevant.66- [ ] Observability added: structured logging, key metrics, tracing for distributed calls.67- [ ] No sensitive data in logs or metrics; correlation IDs propagated.6869---7071## Cross-Skill Integration7273| Situation | Skill to invoke | How |74|-----------|----------------|-----|75| Performance issue in production | **Datadog MCP** | Use `query_metrics`, `search_logs`, `query_traces` (after `/setup`) |76| Optimization changes need review | **code-reviewer** skill | Read `skills/code-reviewer/SKILL.md` |77| Optimization reveals security concern | **security-reviewer** skill | Read `skills/security-reviewer/SKILL.md` |78| Need benchmarks in CI | **ci-cd** skill | Read `skills/ci-cd/SKILL.md` |79| Logging/tracing needs tests | **testing** skill | Read `skills/testing/SKILL.md` |