rust-performance

Diagnose and optimize Rust runtime performance and compile times through measurement-driven profiling and targeted fixes.

3|Updated Aug 8, 2026
One-click install
npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill rust-performance-jose-polanco-oxte
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-performance
Source: https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer/tree/main/.agents/skills/rust/sub-skills/rust-performance
Command: npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill rust-performance-jose-polanco-oxte

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rust code that runs too slowly or compiles too slowly is hard to fix by intuition alone, because the optimizer, cache effects, and allocation patterns behave in non-obvious ways. This Skill enforces a measure-first methodology so you profile before optimizing and re-benchmark every change instead of guessing. ## Core Features & Use Cases - Benchmarking and Profiling: Set up criterion or divan microbenchmarks with correct black_box usage, and profile whole programs with flamegraph, samply, hyperfine, or the dhat heap profiler. - Concrete Optimizations: Apply targeted fixes for hot spots including build configuration (LTO, codegen-units, target-cpu), heap allocation reduction, faster hashing with FxHashMap, type size shrinking, iterator and bounds-check elision, buffered I/O, and SIMD vectorization. - Compile-Time Reduction: Speed up the edit-compile-run loop with faster linkers (mold/lld), dev profile tuning, crate splitting, monomorphization reduction, and sccache caching. - Use Case: A developer notices a Rust CLI processing files too slowly. They establish a criterion baseline, generate a flamegraph revealing hashing dominates, swap HashMap for FxHashMap, and confirm a measurable improvement before keeping the change. ## Quick Start Ask the assistant to profile your Rust project and optimize the hot path using the rust-performance methodology.

Frequently Asked Questions about rust-performance

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I benchmark Rust code with criterion?

Add criterion as a dev-dependency, create a benches file with harness = false, and wrap benchmarked inputs and results in std::hint::black_box so the optimizer cannot eliminate the work. Run cargo bench in release mode; criterion reports percentage changes against the previous run with statistical significance.

How do I find performance bottlenecks in a Rust program?

Profile a release build with cargo flamegraph or samply to find where CPU time goes, and use the dhat heap profiler to find allocation sources that CPU samplers cannot see. Never profile a debug build, since it is 10-100x slower and unrepresentative.

What Cargo settings make Rust release builds faster?

Set lto = "fat", codegen-units = 1, and panic = "abort" in the release profile for often 10-20% runtime improvement with no code changes. Adding target-cpu=native in .cargo/config.toml enables newer CPU instructions but the binary will not run on older processors.

How do I speed up Rust compile times?

Switch to a faster linker like mold on Linux or lld cross-platform, tune the dev profile with line-tables-only debug info, split monolith crates for parallelism, and reduce monomorphization with dyn traits or thin generic shells. Use cargo build --timings first to find the actual bottleneck crates.

When should I replace HashMap with FxHashMap in Rust?

Replace the default SipHash-based HashMap with FxHashMap or ahash when profiling shows hashing is hot and keys are not attacker-controlled. SipHash's collision resistance protects against HashDoS, so keep the default for untrusted input.

Why is my Rust benchmark showing unrealistic results?

The most common causes are benchmarking a debug build and forgetting black_box, which lets the optimizer constant-fold or delete the code under test. Cold-cache first runs and microbenchmarks that do not reflect real input sizes also skew results.