Rust Performance
Official / canonical
- The Rust Performance Book: https://nnethercote.github.io/perf-book/
- Cargo benches: https://doc.rust-lang.org/cargo/reference/profiles.html
- Local catalog:
E:\Code\skills\catalog\sources.yaml→languages_perf
Rules
- Always use
--releasefor runtime perf claims. - Prefer criterion (or built-in benches) over one-off
time. - Fix algorithmic/IO issues before micro-optimizing.
Commands
cargo build --release
cargo test --release
cargo bench
# CPU (Windows: use cargo-instruments on macOS; on Windows try cargo flamegraph / samply if installed)
# cargo install flamegraph
# cargo flamegraph --bin mybin
# Allocation / heap (platform tools vary)
# RUST_LOG=... for app-level timing first
Checklist
- Baseline bench numbers recorded
- Profile under realistic input
- Hot function identified
- Change + bench delta reported
- Unsafe only with clear justification + tests
Related
performance-optimizationtest-driven-developmentfor regression benches- reverse/debug tools only if native ABI issues