agentleFS
gurinderugurinderu/craft/skills/rust-performance/SKILL.md

rust-performance

Skill1 starsChanged 40 days agoMITView on GitHub

Rust performance — measure-first methodology, benchmarking (criterion/divan), profiling, concrete optimizations (build config, allocations, hashing, type sizes, iterators), and cutting compile times. Use when code is slow, optimizing a hot path, choosing a profiler, or when builds are slow. Triggers: criterion, divan, flamegraph, FxHashMap, LTO, PGO, jemalloc, dhat, compile times, mold, sccache.

12 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use rust-unsafe-ffi, rust-api-design and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • botirkhaltaevSkill

    rust-unsafe-ffi

    Master unsafe Rust, FFI, and foreign function interface programming. Use when writing unsafe Rust code with raw pointers, interfacing with C/C++ libraries, creating bindings with bindgen, implementing zero-cost abstractions, working with uninitialized memory, or understanding the safety/unsafety boundary.

    Also in 3 projects that use this

  • adxptivedSkill

    rust-api-design

    Rust API Design guidelines, naming conventions, and best practices. Use when: - User is designing a library, crate, or public APIs - Implementing patterns like Builder, Typestate, or Extension traits - Designing public structures, enums, or traits - Working with common traits (From/Into, Default, AsRef, Debug, Clone) - Applying #[must_use] or #[non_exhaustive] attributes - Restricting trait implementation via Sealed Traits - Formatting naming structures and lifetime designs

    Also in 4 projects that use this

  • DankosikSkill

    rust-debugging

    Causality. Use for an uncertain Rust CLI defect, panic, hang, incorrect output, resource leak, or platform-dependent failure.

    Also in 3 projects that use this

  • codecharmhqSkill

    rust-error-handling

    Use when writing Rust error types, choosing between Result and panic, or when building library error APIs with thiserror/anyhow

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Profile to find the hot spot: Don't optimize where you *think* time goes — measure it (cargo flamegraph, samply, perf.

    line 31
  2. Distinctive:

    Re-measure: Keep the change only if the benchmark moved.

    line 35
  3. Distinctive:

    Before touching code, these settings often buy 10–20% with zero source changes (full toml and tradeoffs in optimizing.md):

    line 43
  4. Distinctive:

    When the profiler points at code, the usual culprits — each with concrete fixes in optimizing.md:

    line 68

“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Performance

Performance work is a loop: measure → profile → fix the hot spot → re-measure. Most of the craft is not writing clever code — it's refusing to optimize anything you haven't measured. Concrete techniques distilled from the Rust Performance Book are in the sub-files.

When to Use

  • Code is too slow and you need to find out why
  • Optimizing a known hot path
  • Choosing a benchmarking tool or profiler
  • Tuning build/compile settings for speed or size
  • The edit→compile→run loop is too slow — cutting compile times (compile-times.md)

The discipline: measure, don't guess

Intuition about Rust performance is wrong more often than not — the optimizer, cache effects, and allocation patterns dominate in non-obvious ways. The rule:

  1. Build in release. --release (or cargo bench). A debug build is 10–100× slower and tells you nothing about real performance — never benchmark or profile a dev build.
  2. Establish a baseline. Benchmark the current code so you can prove a change helped (benchmarking.md).
  3. Profile to find the hot spot. Don't optimize where you think time goes — measure it (cargo flamegraph, samply, perf; allocation volume won't show in a CPU profile — use a heap profiler, dhat). Optimize the top of the profile, nothing else.
  4. Apply a targeted fix (optimizing.md) — one change at a time.
  5. Re-measure. Keep the change only if the benchmark moved; revert if not. "Tiny changes in memory layout can cause significant but ephemeral fluctuations" — confirm, don't assume.

Algorithmic complexity beats micro-optimization: an O(n²)→O(n log n) change outweighs any amount of allocation tuning. Fix the algorithm first, then the constants.

Free wins — build configuration

Before touching code, these settings often buy 10–20% with zero source changes (full toml and tradeoffs in optimizing.md):

[profile.release]
lto = "fat"            # cross-crate inlining: 10-20%+, slower compile
codegen-units = 1      # more optimization, slower compile
panic = "abort"        # smaller/faster, no unwinding
# .cargo/config.toml — newer CPU instructions (binary won't run on older CPUs)
[build]
rustflags = ["-C", "target-cpu=native"]

The other axis — faster builds, not faster binaries

Everything above tunes the build for a faster runtime binary, at the cost of compile time (lto, codegen-units = 1). The opposite goal — a faster edit→compile→run loop — is its own toolkit: switch to a fast linker (mold/lld), tune the dev profile, split a monolith crate so rustc parallelizes and rebuilds incrementally, and cut monomorphization bloat. Several knobs flip between the two axes, so keep them straight → compile-times.md.

Where time and memory usually go

When the profiler points at code, the usual culprits — each with concrete fixes in optimizing.md:

SymptomLook at
lots of malloc/free, Vec growthheap allocations — with_capacity, reuse, smallvec, Box<[T]>, arenas (bumpalo), compact strings; swap the global allocator (jemalloc/mimalloc); find them with dhat
hashing hot, many HashMap lookupsswap SipHash for FxHashMap/ahash
big memcpy, large stack framestype sizes — box large enum variants, smaller ints
tight loops with indexingiterators (often elide bounds checks); autovectorize the hot loop; avoid redundant work
release binary already LTO'd, still need moreprofile-guided optimization (PGO); #[cold] on slow paths
slow stdout / many small reads or writesI/O — buffer (BufReader/BufWriter), lock stdout once, read_until

Boundaries

  • Correctness tests for the code you're optimizing → rust-testing. Performance changes are exactly when a regression test pays off.
  • Safe SIMD (autovectorization, std::simd, wide/pulp) is covered here. get_unchecked, architecture-specific intrinsics (std::arch, target_feature) and other unsafe speedups → rust-unsafe; reach for them only after the safe options and with a benchmark proving the win.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.