rust-performancelisted
Install: claude install-skill po4yka/rust-skills
# Rust Performance
Profiling and optimization for Rust workloads on the host, on Android, and on iOS.
## Rules of engagement
1. Measure before you change code. A profile or a benchmark must name the hotspot.
2. Write down the metric first. Choose one number per concern: items/sec, MB/s, ms per pass, peak MB, or KB added to the app bundle. An optimization without a metric is a guess.
3. Profile the profile that ships. Size and speed numbers from `dev` do not transfer to `release`.
4. Change one thing per measurement. Save a baseline, apply one change, compare.
5. Keep the same machine, the same power state, and the same device for A/B runs.
6. Optimize the algorithm before the constant factor. LTO gives 5-30%; a better data structure gives more.
## Tool selection
| Target | CPU profile | Heap profile | Notes |
|--------|-------------|--------------|-------|
| Host (Linux) | `samply`, `cargo flamegraph`, `perf record` | `heaptrack`, DHAT | `perf_event_paranoid <= 1` required |
| Host (macOS) | `samply`, `cargo flamegraph` (DTrace), Instruments | DHAT through the `dhat` crate, Instruments Allocations | DTrace needs `sudo` and SIP consideration; `samply` does not |
| Android | `simpleperf`, Perfetto | Android Studio native allocations, HWASan for errors | `perf`, `heaptrack` and DHAT do not work here |
| iOS | Instruments Time Profiler, `os_signpost` | Instruments Allocations and Leaks | No `simpleperf`; MetricKit for production data |
`samply` 0.13.1 is the lowest-friction