
rust
Rust performance optimization guidelines. This skill should be used when writing, reviewing, or refactoring Rust code to ensure optimal performance patterns. Triggers on tasks involving memory allocation, ownership, borrowing, iterators, async code, or performance optimization.
Rust performance optimization guidelines. This skill should be used when writing, reviewing, or refactoring Rust code to ensure optimal performance patterns. Triggers on tasks involving memory allocation, ownership, borrowing, iterators, async code, or performance optimization.
Community Rust Best Practices
Comprehensive performance optimization guide for Rust applications. Contains 42 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new Rust code
- Optimizing memory allocation and ownership patterns
- Working with iterators and collections
- Writing async code with Tokio or other runtimes
- Reviewing code for performance issues
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Memory Allocation | CRITICAL | mem- |
| 2 | Ownership & Borrowing | CRITICAL | own- |
| 3 | Data Structure Selection | HIGH | ds- |
| 4 | Iterator & Collection Patterns | HIGH | iter- |
| 5 | Async & Concurrency | MEDIUM-HIGH | async- |
| 6 | Algorithm Complexity | MEDIUM | algo- |
| 7 | Compile-Time Optimization | MEDIUM | comp- |
| 8 | Micro-optimizations | LOW | micro- |
Quick Reference
1. Memory Allocation (CRITICAL)
mem-avoid-unnecessary-clone- Avoid unnecessary clone callsmem-preallocate-vec-capacity- Preallocate Vec capacitymem-use-cow-for-conditional-ownership- Use Cow for conditional ownershipmem-use-arc-for-shared-immutable-data- Use Arc for shared immutable datamem-avoid-format-for-simple-concatenation- Avoid format! for simple concatenationmem-use-smallvec-for-small-collections- Use SmallVec for small collections
2. Ownership & Borrowing (CRITICAL)
own-accept-str-slice-not-string- Accept &str instead of &Stringown-accept-slice-not-vec- Accept &[T] instead of &Vecown-use-into-for-flexible-ownership- Use Intofor flexible ownership own-return-borrowed-when-possible- Return borrowed data when possibleown-use-asref-for-generic-borrows- Use AsReffor generic borrows
3. Data Structure Selection (HIGH)
ds-use-hashset-for-membership- Use HashSet for membership testsds-use-hashmap-for-key-lookup- Use HashMap for key-value lookupsds-use-btreemap-for-sorted-iteration- Use BTreeMap for sorted iterationds-use-vecdeque-for-queue-operations- Use VecDeque for queue operationsds-use-entry-api-for-conditional-insert- Use Entry API for conditional insert
4. Iterator & Collection Patterns (HIGH)
iter-chain-instead-of-intermediate-collect- Chain iterators instead of intermediate collectiter-use-iter-over-into-iter-when-borrowing- Use iter() over into_iter() when borrowingiter-use-filter-map-for-combined-operations- Use filter_map for combined operationsiter-use-flat-map-for-nested-iteration- Use flat_map for nested iterationiter-use-extend-for-bulk-append- Use extend() for bulk appenditer-use-fold-for-accumulation- Use fold() for complex accumulation
5. Async & Concurrency (MEDIUM-HIGH)
async-avoid-blocking-in-async-context- Avoid blocking in async contextasync-use-join-for-concurrent-futures- Use join! for concurrent futuresasync-use-rwlock-over-mutex-for-read-heavy- Use RwLock over Mutex for read-heavyasync-minimize-lock-scope- Minimize lock scopeasync-use-buffered-for-bounded-concurrency- Use buffered() for bounded concurrencyasync-avoid-holding-lock-across-await- Avoid holding lock across await
6. Algorithm Complexity (MEDIUM)
algo-avoid-nested-loops-for-lookup- Avoid nested loops for lookupsalgo-use-binary-search-for-sorted-data- Use binary search for sorted dataalgo-use-sort-unstable-when-order-irrelevant- Use sort_unstable when order irrelevantalgo-use-select-nth-unstable-for-partial-sort- Use select_nth_unstable for partial sortalgo-use-chunks-for-batch-processing- Use chunks() for batch processing
7. Compile-Time Optimization (MEDIUM)
comp-use-const-for-compile-time-computation- Use const for compile-time computationcomp-prefer-static-dispatch- Prefer static dispatch over dynamiccomp-reduce-monomorphization-bloat- Reduce monomorphization bloatcomp-use-const-generics-for-array-sizes- Use const generics for array sizescomp-avoid-repeated-parsing-of-static-data- Avoid repeated parsing of static data
8. Micro-optimizations (LOW)
micro-use-inline-for-small-functions- Apply inline attribute to small hot functionsmicro-avoid-bounds-checks-in-hot-loops- Avoid bounds checks in hot loopsmicro-use-wrapping-arithmetic-when-safe- Use wrapping arithmetic when safemicro-use-byte-literals-for-ascii- Use byte literals for ASCII
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Full Compiled Document
For a comprehensive guide with all rules in a single document, see AGENTS.md.
Reference Files
| File | Description |
|---|---|
| AGENTS.md | Complete compiled guide with all rules |
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
You Might Also Like
Related Skills

coding-agent
Run Codex CLI, Claude Code, OpenCode, or Pi Coding Agent via background process for programmatic control.
openclaw
add-uint-support
Add unsigned integer (uint) type support to PyTorch operators by updating AT_DISPATCH macros. Use when adding support for uint16, uint32, uint64 types to operators, kernels, or when user mentions enabling unsigned types, barebones unsigned types, or uint support.
pytorch
at-dispatch-v2
Convert PyTorch AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code. Use when porting AT_DISPATCH_ALL_TYPES_AND*, AT_DISPATCH_FLOATING_TYPES*, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.
pytorch
skill-writer
Guide users through creating Agent Skills for Claude Code. Use when the user wants to create, write, author, or design a new Skill, or needs help with SKILL.md files, frontmatter, or skill structure.
pytorch
implementing-jsc-classes-cpp
Implements JavaScript classes in C++ using JavaScriptCore. Use when creating new JS classes with C++ bindings, prototypes, or constructors.
oven-sh
implementing-jsc-classes-zig
Creates JavaScript classes using Bun's Zig bindings generator (.classes.ts). Use when implementing new JS APIs in Zig with JSC integration.
oven-sh