full-stack-skills/rust-skills

rust-performance

Measure, profile, optimize, and regression-test Rust performance across latency, throughput, CPU, allocations, memory, binary size, and compile time using representative workloads, Criterion, iai-callgrind, cargo-flamegraph, samply, DHAT, heap or pprof tool…

Voir la source
Document Skill original

Rendu depuis le dépôt source en conservant titres, exemples, code, tableaux, liens et images.

Rust Performance

Optimize from evidence. Define the user-visible metric, reproduce the workload, establish a stable baseline, profile the dominant cost, change one cause, and prove both correctness and improvement.

Scope and Routing

Use this skill for microbenchmarks, end-to-end load tests, CPU profiles, allocation and heap analysis, binary size, compile time, cache behavior, and regression budgets.

Route concurrency semantics to rust-concurrency, telemetry pipelines to rust-observability, general test architecture to rust-testing, release profiles and features to rust-cargo-build, and semantic review to rust-code-review.

Workflow

1. Define the performance contract

Record the workload, dataset, inputs, concurrency, platform, CPU and memory limits, toolchain, target, features, allocator, build profile, warm-up, cache state, and success metrics. Distinguish throughput from p50/p95/p99 latency and steady-state from startup or shutdown.

Do not optimize debug builds or synthetic inputs unless they represent the actual problem.

2. Establish a reproducible baseline

  • Verify correctness before benchmarking.
  • Use release-like optimization, codegen units, LTO, panic strategy, and target CPU settings intentionally.
  • Isolate background load, power management, thermal throttling, and noisy shared runners.
  • Record raw samples and uncertainty, not only one average.
  • Compare the same commit, toolchain, dependency graph, and hardware when enforcing small regressions.

Read Benchmarking and Regression Gates.

3. Choose the measurement layer

QuestionTool or evidence
Is a pure operation faster?Criterion or Divan microbenchmark
Did instruction-level cost change?iai-callgrind on supported systems
Where is CPU time spent?samply, cargo-flamegraph, Instruments, perf, pprof
Where are allocations retained?DHAT, heap profiler, allocator metrics
Why is the binary large?cargo-bloat and feature inspection
What drives compile time?Cargo build timings and cargo-llvm-lines
Does the service meet its SLO?Representative load test plus observability

A microbenchmark does not prove end-to-end latency, overload behavior, or memory bounds.

4. Profile before editing

Capture a profile under the failing workload. Preserve symbols and use the same optimized artifact intended for comparison. Separate on-CPU work, waiting, lock contention, I/O, allocation, page faults, and scheduler overhead. Read CPU and Latency Profiling.

5. Optimize the dominant cause

Common changes include algorithmic complexity, fewer passes, better batching, avoiding repeated parsing or allocation, borrowing instead of cloning, data-layout improvements, reduced synchronization, bounded queues, streaming, feature reduction, and moving CPU work off async workers.

Do not use unsafe, custom allocators, SIMD, lock-free structures, or caching until simpler changes are insufficient and invariants plus fallback behavior are tested.

6. Measure memory, size, and build cost

Track peak RSS, retained heap, allocation rate, fragmentation, cache growth, buffer bounds, binary sections, monomorphization, debug information, enabled features, macro expansion, and incremental versus clean compile time. Read Memory, Binary Size, and Compile Time.

7. Prove the result

Rerun correctness tests and the exact baseline protocol. Report absolute and relative results, variance, hardware and software context, tradeoffs, and regressions in secondary metrics. Add a durable benchmark or budget only when the environment can detect the intended threshold reliably.

Completion Criteria

  • Define a representative workload and user-visible metric.
  • Record reproducible baseline evidence before optimization.
  • Profile and identify the dominant cost rather than guessing.
  • Preserve correctness and safety through targeted tests.
  • Re-measure under the same protocol and report uncertainty plus tradeoffs.
  • Add a stable regression check or explain why the environment is too noisy.

Resources

Upstream Sources

Data Privacy

This skill does not collect, store, or transmit user data. Profiles, heap dumps, command lines, symbols, and benchmark datasets may contain sensitive information; confirm storage and upload policy before sharing them.

du même dépôt

Autres Skills

Tous les Skills
full-stack-skills
Communauté

rust-api-design

Design Rust library APIs that follow the Rust API Guidelines — naming (C-CASE, C-CONV, C-GETTER), interop traits (C-COMMON-TRAITS, C-CONVERT, C-ITER, C-SERDE), predictability (C-INTUITIVE, C-CONST), flexibility (C-GENERIC, C-NEWTYPE, C-EXT), type safety (C-BOOL, C-NONZERO, C-WRAPPER, C-STR), dependability (C-PANIC, C-UNWRAP), debuggability (C-DEBUG), and future-proofing (C-SEALED, C-STRUCT-FIELD, C-NON-EXHAUSTIVE). Use when users design a public crate API, choose between generics/concrete/newtype, decide trait bounds, hide implementation, avoid breakage, or ask "what is idiomatic Rust API design"; hand semver and publish workflow to rust-semver, lint config to rust-style-clippy, and in-crate layout to rust-module-layout.

installations
1
GitHub Stars
5
Mis à jour
19 sept.
full-stack-skills
Communauté

rust-by-example

Show Rust patterns through short compilable examples — type conversions (From/Into/TryFrom/as/Deref), flow control (if let/while let/match/loop), functions and closures (Fn/FnMut/FnOnce, captures), modules (mod/use/pub/super/self), generics and traits (bounds/associated types/trait objects), error handling (?/Result/thiserror/anyhow), attributes (derive/cfg/inline/allow), unsafe (raw pointers/unions/ABI), procedural macros (derive/attribute/function-like), and inline asm. Use when users ask "how do I write X in Rust", need a concrete pattern with copy-pasteable code, or are migrating from Java/Python/Go/C++ and want the Rust equivalent; hand architecture decisions to rust-api-design/rust-workspace, std API selection to rust-stdlib, and async runtime to rust-concurrency.

installations
1
GitHub Stars
5
Mis à jour
19 sept.
full-stack-skills
Communauté

rust-cargo-build

Configure, operate, diagnose, and automate Cargo for Rust packages and workspaces. Cover manifests and targets, commands, dependency resolution and features, profiles, build scripts, configuration and environment variables, caches and build diagnostics, cross-compilation, registries, packaging, publishing, metadata, CI reproducibility, and stable-versus-nightly feature gates. Use for Cargo.toml, Cargo.lock, .cargo/config.toml, cargo build/check/run/tree/metadata/package/publish, resolver or feature problems, build output and performance, private registries, and beginner Cargo workflows. Route crate selection and supply-chain audits to rust-dependencies, workspace topology to rust-workspace, test design to rust-testing, documentation design to rust-documentation, lint policy to rust-style-clippy, and API compatibility decisions to rust-semver.

installations
1
GitHub Stars
5
Mis à jour
19 sept.
full-stack-skills
Communauté

rust-cli

Design, implement, test, and release production Rust command-line applications, including command contracts, subcommands, configuration precedence, stdin/stdout/stderr, exit codes, file safety, daemon IPC, terminal handling, packaging, and process-level tests. Use when users ask for a Rust CLI, command parser, clap integration, Unix-style pipelines, daemon clients, PTY/TUI behavior, shell completion, or CLI release engineering.

installations
1
GitHub Stars
5
Mis à jour
19 sept.