Performance & Optimization
Rust performance work starts with clear code, then uses profiling and benchmarking to justify targeted changes.
Concepts
Patterns
- Benchmarking with Criterion
- Flamegraph and perf Workflow
- Reducing Heap Allocations
- Allocator Choices
- Bounds-Check Elimination
- Cache-Friendly Data Layout
- SmallVec for Inline Storage
- Arena Allocation
- LTO and codegen-units
Antipatterns
Neighboring Notes
- Profiles and Optimization Settings
- Codegen and Optimization Flags
- Zero-Cost Abstractions
- Capacity and Reallocation
- Manual Index Loops for Speed
- Needless Clone
- Unnecessary Collect
- Prefer Iterator Pipelines to Manual Indexing
Sources
- The Rust Programming Language, ch. 13.4 “Comparing Performance: Loops vs. Iterators” — the-book, https://doc.rust-lang.org/book/ch13-04-performance.html
- The Rust Programming Language, ch. 14.1 “Customizing Builds with Release Profiles” — the-book, https://doc.rust-lang.org/book/ch14-01-release-profiles.html
- The Cargo Book, “Profiles” — cargo-book, https://doc.rust-lang.org/cargo/reference/profiles.html
- The Rust Reference, “Code generation attributes: inline” — the-reference, https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
