// Establish performance baselines and detect regressions using flamegraph analysis. Use when optimizing performance-critical code, investigating performance issues, or before creating commits with performance-sensitive changes.
| name | analyze-performance |
| description | Establish performance baselines and detect regressions using flamegraph analysis. Use when optimizing performance-critical code, investigating performance issues, or before creating commits with performance-sensitive changes. |
Follow these steps to analyze performance and detect regressions:
Run the automated benchmark script to collect current performance data:
./run.fish run-examples-flamegraph-fold --benchmark
What this does:
tui/flamegraph-benchmark.perf-foldedImplementation details:
script-lib.fishCompare the newly generated flamegraph with the baseline:
Baseline file:
tui/flamegraph-benchmark-baseline.perf-folded
Current file:
tui/flamegraph-benchmark.perf-folded
The baseline file contains:
Compare the two flamegraph files to identify regressions or improvements:
Key metrics to analyze:
Hot path changes
Sample count changes
Call stack depth changes
New allocations or I/O
Create a comprehensive report analyzing the performance changes:
Report structure:
# Performance Regression Analysis
## Summary
[Overall performance verdict: regression, improvement, or neutral]
## Hot Path Changes
- Function X: 1500 โ 2200 samples (+47%) โ ๏ธ REGRESSION
- Function Y: 800 โ 600 samples (-25%) โ
IMPROVEMENT
- Function Z: NEW in current (300 samples) ๐ INVESTIGATE
## Top 5 Most Expensive Functions
### Baseline
1. render_loop: 3500 samples
2. paint_buffer: 2100 samples
3. diff_algorithm: 1800 samples
...
### Current
1. render_loop: 3600 samples (+3%)
2. paint_buffer: 2500 samples (+19%) โ ๏ธ
3. diff_algorithm: 1700 samples (-6%) โ
...
## Regressions Detected
[List of functions with significant increases]
## Improvements Detected
[List of functions with significant decreases]
## Recommendations
[What should be investigated or optimized]
Present the regression report to the user with:
When to update the baseline:
Only update when you've achieved a new "best" performance state:
How to update:
# Replace baseline with current
cp tui/flamegraph-benchmark.perf-folded tui/flamegraph-benchmark-baseline.perf-folded
# Commit the new baseline
git add tui/flamegraph-benchmark-baseline.perf-folded
git commit -m "perf: Update performance baseline after optimization"
See baseline-management.md for detailed guidance on when and how to update baselines.
The .perf-folded files contain stack traces with sample counts:
main;render_loop;paint_buffer;draw_cell 45
main;render_loop;diff_algorithm;compare 30
Format:
1. Make code change
โ
2. Run: ./run.fish run-examples-flamegraph-fold --benchmark
โ
3. Analyze flamegraph vs baseline
โ
4. โโ Performance improved?
โ โโ YES โ Update baseline, commit
โ โโ NO โ Investigate regressions, optimize
โโ Repeat
For more granular performance analysis, consider:
Run benchmarks for specific functions:
cargo bench
When to use:
#[bench]Generate visual flamegraph SVG:
cargo flamegraph
When to use:
Requirements:
flamegraph crate installedFor deep investigation:
# Profile with perf
perf record -F 999 --call-graph dwarf ./target/release/app
# Generate flamegraph
perf script | stackcollapse-perf.pl | flamegraph.pl > flame.svg
When analyzing flamegraphs, watch for:
render_loop;Vec::push;alloc::grow 500 samples โ ๏ธ
Problem: Allocating in tight loops Fix: Pre-allocate or use capacity hints
process_data;String::clone 300 samples โ ๏ธ
Problem: Unnecessary data copies
Fix: Use references or Cow<str>
a;b;c;d;e;f;g;h;i;j;k;l;m 50 samples โ ๏ธ
Problem: Too much abstraction or recursion Fix: Flatten, inline, or optimize
render_loop;write;syscall 200 samples โ ๏ธ
Problem: Blocking I/O in rendering Fix: Buffer or defer I/O
After performance analysis:
This skill includes additional reference material:
baseline-management.md - Comprehensive guide on when and how to update performance baselines: when to update (after optimization, architectural changes, dependency updates, accepting trade-offs), when NOT to update (regressions, still debugging, experimental code, flaky results), step-by-step update process, baseline update checklist, reading flamegraph differences, example workflows, and common mistakes. Read this when:
check-code-quality - Run before performance analysis to ensure correctnesswrite-documentation - Document performance characteristics/check-regression - Explicitly invokes this skillperf-checker - Agent that delegates to this skilltui/*.perf-folded filesscript-lib.fishflamegraph.pl to generate SVGs