| name | performance-analyzer |
| description | This skill should be used when code is reported slow, before suggesting any optimization, when choosing between "cprof/eprof/fprof/tprof", or when creating "Benchee benchmarks" to compare approaches |
Performance Analysis for Elixir/Phoenix
Overview
NO OPTIMIZATION WITHOUT PROFILING DATA. Code review cannot tell you where bottlenecks are ā only measurement can. Refuse to suggest optimizations without profiling results.
Profiler Selection
| What You Need | Tool | Command |
|---|
| Function call frequency | cprof | mix profile.cprof -e "Code.here()" |
| Time per function | eprof | mix profile.eprof -e "Code.here()" |
| Detailed call tree | fprof | mix profile.fprof -e "Code.here()" |
| Memory allocations (OTP 27+) | tprof | mix profile.tprof -e "Code.here()" --type memory |
Start with eprof (lower overhead). Use fprof only when you need call trees.
Escalation Ladder
Do you have a number for "how slow"?
NO ā L0: Measure first (Benchee baseline)
YES ā Know WHERE time is spent?
NO ā L1: Profile (eprof/fprof)
YES ā Algorithmic problem (O(n²)+)?
YES ā L2: Algorithm/data structure fix
NO ā CPU-bound?
YES ā L3: BEAM opts (Task.async_stream, ETS)
NO ā Database/I/O?
YES ā L4: DB optimization (preload, indexes)
NO ā L5: System tuning (last resort)
Common Mistakes
- Optimizing without profiling ā code review ā profiling. Measure first.
- No baseline benchmark ā measure current state before changing anything
- Assuming optimization worked ā benchmark after changes to verify
- Server-side metrics only ā client-observed latency can be 15x higher
- Wrong profiler ā fprof measures time not memory; cprof counts calls not time
Reference Files
Read the file that matches your current problem:
profiling.md ā When: About to profile code or choosing a profiler. Iron Law enforcement, profiler usage, escalation ladder L0-L5, common patterns
benchmarking.md ā When: Comparing implementation alternatives with Benchee. Benchee templates, complexity analysis, validation workflow
latency.md ā When: Investigating tail latency or fan-out amplification. Tail latency reduction (hedged requests), fan-out amplification, measurement pitfalls, pool sizing
beam-gc.md ā When: Suspecting garbage collection pressure or large heaps. Per-process GC, ETS for heap reduction, 4 mitigation techniques
beam-efficiency.md ā When: Hitting BEAM-specific performance pitfalls (binaries, maps, lists). BEAM performance pitfalls: Seven Myths, binary handling (IO lists, append vs prepend), map efficiency (32-key threshold, key sharing), list O(n) traps, process data copying, atom table, NIFs
Commands
/benchmark ā Create and run Benchee benchmarks for comparison
/review [file] ā Review code including performance analysis
Related Skills
- algorithms: Better data structures when profiling reveals O(n²)+
- production-quality: Observability and telemetry setup
- elixir-patterns: BEAM-specific patterns (ETS, Task, GenServer)