rust-performance

Profile and optimize Rust code using criterion benchmarks, flamegraph, and compiler tuning.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/luckyegg168/rust-skill --skill rust-performance-luckyegg168
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-performance
Source: https://github.com/luckyegg168/rust-skill/tree/main/rust-skills/rust-performance
Command: npx skills add https://github.com/luckyegg168/rust-skill --skill rust-performance-luckyegg168

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires criterion, dhat, bumpalo, ahash, rustc-hash, and includes references (resource) components.

What problem does it solve? Rust developers often struggle to locate performance bottlenecks, choose the right compiler optimization settings, and verify that optimizations actually improve runtime. This Skill provides structured guidance for profiling, benchmarking, and optimizing Rust programs with measurable results. ## Core Features & Use Cases - Benchmarking with Criterion: Set up criterion 0.5 micro-benchmarks with benchmark groups, throughput metrics, and input-size comparisons to quantify optimization effects. - Profiling Toolchain: Use cargo flamegraph, perf, DHAT, and cargo-show-asm to identify CPU hotspots, heap allocation patterns, and verify inlining or vectorization. - Compiler & Memory Optimization: Configure Cargo profiles (opt-level, LTO, codegen-units), select fast HashMap hashers (ahash, FxHash), apply arena allocators (bumpalo), and design SIMD-friendly SoA data layouts. - Use Case: When a Rust service shows high latency, use this Skill to generate a flamegraph, identify that unnecessary .clone() calls dominate the hot path, replace them with borrows or Cow, and confirm the improvement with a criterion baseline comparison. ## Quick Start Ask the AI to help you set up a criterion benchmark and flamegraph profiling workflow to find and fix the performance bottleneck in your Rust function.

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 0.5 to dev-dependencies with the html_reports feature, create a [[bench]] target with harness = false, and define benchmark functions using Criterion, BenchmarkId, and black_box. Run cargo bench to execute benchmarks and generate comparison reports.

How to generate a flamegraph for a Rust application?▼

Install the tool with cargo install flamegraph, ensure your profile keeps debug symbols (debug = true in the bench profile), then run cargo flamegraph --bin your_app. It produces a flamegraph.svg showing CPU hotspots; on Linux you may need to adjust perf_event_paranoid.

Which hasher is fastest for Rust HashMap?▼

FxHash from rustc-hash is fastest for integer keys but lacks DoS protection. AHash offers strong speed with DoS resistance for general use. The default SipHash is safest for untrusted external input but slower than both alternatives.

Why is my Rust program slow in debug mode?▼

Debug builds use opt-level = 0 with no inlining or vectorization, making iterators far slower than release builds. Always measure performance with cargo build --release, or set opt-level = 1 in the dev profile for a faster development loop.

When should I use an arena allocator like bumpalo in Rust?▼

Use bumpalo when allocating many short-lived small objects such as AST or graph nodes. Arena allocation uses a fast bump pointer, keeps memory cache-friendly in one contiguous block, and frees everything at once when the arena drops.

Does #[inline] always improve Rust performance?▼

No. Within a single crate the compiler usually decides inlining well on its own, and generic functions are already monomorphized. Use #[inline] mainly for small public functions crossing crate boundaries, and reserve #[inline(always)] for cases proven by benchmarks.