Skip to content

Performance Way

Source: hooks/ways/softwaredev/code/performance/performance.md

Frontmatter
Field Value
description performance optimization, profiling, benchmarking, latency
vocabulary optimize profile benchmark latency throughput memory cache bottleneck flamegraph allocation heap speed slow performance
pattern slow|optimi|latency|cpu.?profil|flamegraph|speed.?up|benchmark|bottleneck|throughput|memory.?leak
refire 0.2
scope agent, subagent
pattern_keep slow

What Claude Should Do

When asked about performance, start with static analysis — don't just say "profile it":

  1. Scan for algorithmic issues: nested loops over collections (O(n^2)), repeated database/API calls inside loops (N+1), string concatenation in tight loops
  2. Identify the pattern, show the fix:
  3. N+1 queries → batched query or join (show the rewrite)
  4. Repeated computation → memoize or cache (show before/after)
  5. Unnecessary allocation → pre-allocate or reuse (show the change)
  6. Suggest profiling tools for the detected language:
  7. Python: cProfile, py-spy, memory_profiler
  8. Node.js: --prof, clinic.js, 0x
  9. Rust: cargo flamegraph, criterion for benchmarks
  10. Go: pprof, benchstat

Generate Measurements

When the user wants to benchmark, produce before/after measurement code — don't just suggest "measure it".

Avoid

  • Suggesting "just profile it" without analyzing the code first
  • Micro-optimizations that hurt readability
  • Caching without specifying an invalidation strategy