rust-hot-path

Applies measured Rust optimizations for allocations, type sizes, hashers, bounds checks, inlining, and buffered I/O.

2|1|Updated Aug 19, 2026
One-click install
npx skills add https://github.com/po4yka/rust-skills --skill rust-hot-path-po4yka
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-hot-path
Source: https://github.com/po4yka/rust-skills/tree/main/skills/rust-hot-path
Command: npx skills add https://github.com/po4yka/rust-skills --skill rust-hot-path-po4yka

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? After a profiler or benchmark names a hot spot in Rust code, it is unclear which concrete code change will actually pay off. This Skill turns a profile into a diff: it routes symptoms like hot malloc, memcpy, SipHasher, or panic_bounds_check entries to specific, measured fixes with verification commands and guardrails. ## Core Features & Use Cases - Symptom-to-fix routing: A triage table maps profile signals (allocation rate, syscall dominance, missing vectorization) to sections covering hasher choice, BufWriter buffering, with_capacity/reserve_exact/clone_from, type shrinking, bounds-check removal, and inline/cold attribute placement. - Verification and pinning: Provides assembly probes (grep -c panic_bounds_check), -Zprint-type-sizes dumps, nm symbol checks, dhat allocation-count tests, and gated const size asserts so each optimization is proven and protected from future refactors. - Deep reference material: Four reference files hold full hasher benchmarks, SmallVec/ArrayVec sizing tables, inlining thresholds and MIR budgets, and clippy lint gates. - Use Case: A profile shows __rust_alloc dominating a parser. The Skill directs you to replace per-line lines() allocation with read_line into one cleared buffer, then pin the result with a dhat test asserting one allocation. ## Quick Start Ask the agent to reduce allocations in the named hot function using the rust-hot-path rules and to prove the win with a dhat allocation-count test.

Frequently Asked Questions about rust-hot-path

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

FAQPage Schema
How do I reduce allocations in Rust hot code?▼

Use `Vec::with_capacity` for known lengths, `clone_from` to reuse destination buffers, keep one workhorse buffer cleared per loop iteration, and give iterators an exact `size_hint`. Pin the result with a `dhat` heap test asserting the allocation count.

FxHashMap vs std HashMap: which hasher should I use in Rust?▼

Keep std `RandomState` for keys controlled outside the process since its per-process seed is the HashDoS defence. Use `rustc_hash::FxHashMap` for internal keys, `ahash::RandomState` for untrusted keys when hashing is measured hot, and `nohash_hasher::IntMap` for dense integer ids.

Why is println! slow in a Rust loop and how do I fix it?▼

`Stdout` is a `LineWriter`, so it issues one write syscall per newline even when the lock is held. Wrap `stdout().lock()` in a `BufWriter` and end with an explicit `flush()?`, since a dropped `BufWriter` silently discards the final write error.

How do I remove bounds checks in Rust loops?▼

Prefer iterating with `v.iter()`, reslicing with `&v[..n]` before indexing, or asserting `n <= v.len()` once ahead of the loop. Confirm removal by counting `panic_bounds_check` in emitted assembly with the probe function marked `#[inline(never)]`.

When should I use #[inline(always)] or #[cold] in Rust?▼

Only after a measurement names the call site, because rustc already ships small eligible bodies cross-crate without any attribute. Pair `#[cold]` with `#[inline(never)]` since `#[cold]` alone does not prevent inlining of a small callee.

When should I not use this hot-path optimization approach?▼

Do not apply it before profiling: the Skill explicitly requires a measurement pointing at each change, and a better algorithm beats every local rule. For choosing or running a profiler and benchmark setup, use the rust-performance skill instead.