Use when analyzing performance issues, creating benchmarks, or optimizing Elixir/Phoenix code
NO OPTIMIZATION WITHOUT PROFILING DATA. Code review cannot tell you where bottlenecks are ā only measurement can. Refuse to suggest optimizations without profiling results.
| 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.
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)
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 patternsbenchmarking.md ā When: Comparing implementation alternatives with Benchee. Benchee templates, complexity analysis, validation workflowlatency.md ā When: Investigating tail latency or fan-out amplification. Tail latency reduction (hedged requests), fan-out amplification, measurement pitfalls, pool sizingbeam-gc.md ā When: Suspecting garbage collection pressure or large heaps. Per-process GC, ETS for heap reduction, 4 mitigation techniquesbeam-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/benchmark ā Create and run Benchee benchmarks for comparison/review [file] ā Review code including performance analysis