← ClaudeAtlas

rust-performancelisted

Profile before optimizing, cut allocation out of hot paths, and treat LTO, codegen-units, PGO and target-cpu as the last five percent. Use when Rust code is too slow, when a benchmark regresses, when reviewing code that allocates or formats inside a loop, when release-profile or codegen flags come up, or when the user asks how to make Rust faster.
rewrite-rs/skills · ★ 2 · Code & Development · score 73
Install: claude install-skill rewrite-rs/skills
# Rust Performance No change lands here that no measurement named: the profile is the entry ticket, and the codegen flags are the last five percent, not the first move. Async throughput is `/async-rust`; `unsafe` for speed is `/unsafe-rust`. ## Measure, then change No optimisation lands without a measurement that named it. Skipping it costs twice: the change that made nothing faster, and the change that made the code worse in exchange for nothing. A profile finds the one function that holds the time — almost never the one that looked expensive while reading. ## Benchmarks that mean something `criterion` for a statistical comparison against a stored baseline; `divan` when a lighter harness is enough. Benchmark the operation, not the setup around it. Without it, the profiler shows addresses instead of function names: ```toml [profile.bench] debug = 1 ``` A benchmark run on a laptop under thermal throttling produces a number, just not a comparable one — the machine has to be quiet between the runs being compared. ## Allocation is usually the answer The highest-yield category, and the one a profile names most often: - `Vec::with_capacity` when the size is known — the default grows and copies. - Clear-and-reuse over allocate-per-iteration: buffer outside, `clear()` inside. - `Box<[T]>` and `Box<str>` for an owned sequence that will never grow. - `mem::take` to move a value out of a `&mut` without cloning. - No `format!` in a hot loop — every call allocates a fresh `Stri