cargo-toml-optimization
Installation
SKILL.md
Cargo.toml Optimization
Tune a Rust manifest (Cargo.toml) and its build config (.cargo/config.toml) toward one goal at a time. Runtime speed, binary size, compile time, dependency hygiene: these pull against each other, so name the target before editing. Then take a baseline measurement, change a single lever, re-measure.
Measure First
Advice you haven't measured is guessing. opt-level "z" is not always smaller than "s" or 3. Fat LTO can cost minutes of link time for a percent of runtime. The real bottleneck is often one crate on the critical path rather than the whole graph.
| Question | Command |
|---|---|
| What is slow to compile? | cargo build --timings -> HTML report; read the critical path |
| Which deps are duplicated at incompatible versions? | cargo tree -d |
| What makes the binary big? | cargo bloat --release --crates (install cargo-bloat) |
| Why is this feature / crate here? | cargo tree -e features -i <crate> |
Build cache, Cargo.lock rules, build.rs cost: references/how-cargo-works.md.