Performance optimization guide for Rust applications. Contains 42 rules across 8 categories, prioritized by impact from critical (memory allocation, ownership) to incremental (micro-optimizations).
When to Apply
Optimizing Rust code for performance or reducing allocations
Choosing data structures for optimal algorithmic complexity
Working with iterators to avoid unnecessary intermediate allocations
Writing async code with Tokio or other runtimes
Profiling hot paths and eliminating performance bottlenecks
For idiomatic patterns, architecture, and code organization, see rust-refactor skill
1---2name: rust-optimise3description: Rust Optimise Best Practices4---5# Rust Optimise Best Practices67Performance optimization guide for Rust applications. Contains 42 rules across 8 categories, prioritized by impact from critical (memory allocation, ownership) to incremental (micro-optimizations).89## When to Apply1011- Optimizing Rust code for performance or reducing allocations12- Choosing data structures for optimal algorithmic complexity13- Working with iterators to avoid unnecessary intermediate allocations14- Writing async code with Tokio or other runtimes15- Profiling hot paths and eliminating performance bottlenecks16- Reviewing code for performance anti-patterns1718## Rule Categories by Priority1920| Priority | Category | Impact | Prefix |21|----------|----------|--------|--------|22| 1 | Memory Allocation | CRITICAL | `mem-` |23| 2 | Ownership & Borrowing | CRITICAL | `own-` |24| 3 | Data Structure Selection | HIGH | `ds-` |25| 4 | Iterator & Collection Patterns | HIGH | `iter-` |26| 5 | Async & Concurrency | MEDIUM-HIGH | `async-` |27| 6 | Algorithm Complexity | MEDIUM | `algo-` |28| 7 | Compile-Time Optimization | MEDIUM | `comp-` |29| 8 | Micro-optimizations | LOW | `micro-` |3031## Quick Reference3233### 1. Memory Allocation (CRITICAL)3435- [`mem-avoid-unnecessary-clone`](references/mem-avoid-unnecessary-clone.md) - Avoid unnecessary clone calls36- [`mem-preallocate-vec-capacity`](references/mem-preallocate-vec-capacity.md) - Preallocate Vec capacity37- [`mem-use-cow-for-conditional-ownership`](references/mem-use-cow-for-conditional-ownership.md) - Use Cow for conditional ownership38- [`mem-use-arc-for-shared-immutable-data`](references/mem-use-arc-for-shared-immutable-data.md) - Use Arc for shared immutable data39- [`mem-avoid-format-for-simple-concatenation`](references/mem-avoid-format-for-simple-concatenation.md) - Avoid format! for simple concatenation40- [`mem-use-smallvec-for-small-collections`](references/mem-use-smallvec-for-small-collections.md) - Use SmallVec for small collections4142### 2. Ownership & Borrowing (CRITICAL)4344- [`own-accept-str-slice-not-string`](references/own-accept-str-slice-not-string.md) - Accept &str instead of &String45- [`own-accept-slice-not-vec`](references/own-accept-slice-not-vec.md) - Accept &[T] instead of &Vec<T>46- [`own-use-into-for-flexible-ownership`](references/own-use-into-for-flexible-ownership.md) - Use Into<T> for flexible ownership47- [`own-return-borrowed-when-possible`](references/own-return-borrowed-when-possible.md) - Return borrowed data when possible48- [`own-use-asref-for-generic-borrows`](references/own-use-asref-for-generic-borrows.md) - Use AsRef<T> for generic borrows4950### 3. Data Structure Selection (HIGH)5152- [`ds-use-hashset-for-membership`](references/ds-use-hashset-for-membership.md) - Use HashSet for membership tests53- [`ds-use-hashmap-for-key-lookup`](references/ds-use-hashmap-for-key-lookup.md) - Use HashMap for key-value lookups54- [`ds-use-btreemap-for-sorted-iteration`](references/ds-use-btreemap-for-sorted-iteration.md) - Use BTreeMap for sorted iteration55- [`ds-use-vecdeque-for-queue-operations`](references/ds-use-vecdeque-for-queue-operations.md) - Use VecDeque for queue operations56- [`ds-use-entry-api-for-conditional-insert`](references/ds-use-entry-api-for-conditional-insert.md) - Use Entry API for conditional insert5758### 4. Iterator & Collection Patterns (HIGH)5960- [`iter-chain-instead-of-intermediate-collect`](references/iter-chain-instead-of-intermediate-collect.md) - Chain iterators instead of intermediate collect61- [`iter-use-iter-over-into-iter-when-borrowing`](references/iter-use-iter-over-into-iter-when-borrowing.md) - Use iter() over into_iter() when borrowing62- [`iter-use-filter-map-for-combined-operations`](references/iter-use-filter-map-for-combined-operations.md) - Use filter_map for combined operations63- [`iter-use-flat-map-for-nested-iteration`](references/iter-use-flat-map-for-nested-iteration.md) - Use flat_map for nested iteration64- [`iter-use-extend-for-bulk-append`](references/iter-use-extend-for-bulk-append.md) - Use extend() for bulk append65- [`iter-use-fold-for-accumulation`](references/iter-use-fold-for-accumulation.md) - Use fold() for complex accumulation6667### 5. Async & Concurrency (MEDIUM-HIGH)6869- [`async-avoid-blocking-in-async-context`](references/async-avoid-blocking-in-async-context.md) - Avoid blocking in async context70- [`async-use-join-for-concurrent-futures`](references/async-use-join-for-concurrent-futures.md) - Use join! for concurrent futures71- [`async-use-rwlock-over-mutex-for-read-heavy`](references/async-use-rwlock-over-mutex-for-read-heavy.md) - Use RwLock over Mutex for read-heavy72- [`async-minimize-lock-scope`](references/async-minimize-lock-scope.md) - Minimize lock scope73- [`async-use-buffered-for-bounded-concurrency`](references/async-use-buffered-for-bounded-concurrency.md) - Use buffered() for bounded concurrency74- [`async-avoid-holding-lock-across-await`](references/async-avoid-holding-lock-across-await.md) - Avoid holding lock across await7576### 6. Algorithm Complexity (MEDIUM)7778- [`algo-avoid-nested-loops-for-lookup`](references/algo-avoid-nested-loops-for-lookup.md) - Avoid nested loops for lookups79- [`algo-use-binary-search-for-sorted-data`](references/algo-use-binary-search-for-sorted-data.md) - Use binary search for sorted data80- [`algo-use-sort-unstable-when-order-irrelevant`](references/algo-use-sort-unstable-when-order-irrelevant.md) - Use sort_unstable when order irrelevant81- [`algo-use-select-nth-unstable-for-partial-sort`](references/algo-use-select-nth-unstable-for-partial-sort.md) - Use select_nth_unstable for partial sort82- [`algo-use-chunks-for-batch-processing`](references/algo-use-chunks-for-batch-processing.md) - Use chunks() for batch processing8384### 7. Compile-Time Optimization (MEDIUM)8586- [`comp-use-const-for-compile-time-computation`](references/comp-use-const-for-compile-time-computation.md) - Use const for compile-time computation87- [`comp-prefer-static-dispatch`](references/comp-prefer-static-dispatch.md) - Prefer static dispatch over dynamic88- [`comp-reduce-monomorphization-bloat`](references/comp-reduce-monomorphization-bloat.md) - Reduce monomorphization bloat89- [`comp-use-const-generics-for-array-sizes`](references/comp-use-const-generics-for-array-sizes.md) - Use const generics for array sizes90- [`comp-avoid-repeated-parsing-of-static-data`](references/comp-avoid-repeated-parsing-of-static-data.md) - Avoid repeated parsing of static data9192### 8. Micro-optimizations (LOW)9394- [`micro-use-inline-for-small-functions`](references/micro-use-inline-for-small-functions.md) - Apply inline attribute to small hot functions95- [`micro-avoid-bounds-checks-in-hot-loops`](references/micro-avoid-bounds-checks-in-hot-loops.md) - Avoid bounds checks in hot loops96- [`micro-use-wrapping-arithmetic-when-safe`](references/micro-use-wrapping-arithmetic-when-safe.md) - Use wrapping arithmetic when safe97- [`micro-use-byte-literals-for-ascii`](references/micro-use-byte-literals-for-ascii.md) - Use byte literals for ASCII9899## References1001011. [https://nnethercote.github.io/perf-book/](https://nnethercote.github.io/perf-book/)1022. [https://rust-lang.github.io/api-guidelines/](https://rust-lang.github.io/api-guidelines/)1033. [https://doc.rust-lang.org/nomicon/](https://doc.rust-lang.org/nomicon/)1044. [https://tokio.rs/tokio/tutorial](https://tokio.rs/tokio/tutorial)105106## Related Skills107108- For idiomatic patterns, architecture, and code organization, see `rust-refactor` skill
Run npx skillmds@latest add comeonoliver/rust-optimise in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Rust Optimise Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.