maverick-rust-performance
Rust performance optimization and zero-cost abstractions
When & Why to Use This Skill
This Claude skill specializes in Rust performance optimization by identifying inefficient memory allocations and promoting zero-cost abstractions. It helps developers write faster, more memory-efficient code by suggesting improvements for clones, collection preallocations, and iterator usage, ensuring high-performance systems programming standards.
Use Cases
- Identifying and removing redundant .clone() and .to_owned() calls to reduce memory overhead and improve execution speed.
- Optimizing collection handling by suggesting with_capacity to prevent frequent reallocations in performance-critical loops.
- Refactoring imperative loops into high-performance functional iterators to leverage Rust's zero-cost abstractions and compiler optimizations.
- Automated performance auditing during the code review process to catch memory-intensive patterns before they reach production.
| name | maverick-rust-performance |
|---|---|
| description | Rust performance optimization and zero-cost abstractions |
| version | 1.0.0 |
| - Vec | :with_capacity |
| - String | :with_capacity |
Rust Performance Skill
Avoid Unnecessary Clones
// BAD
fn process(s: String) -> String {
let s_copy = s.clone(); // Unnecessary!
s_copy.to_uppercase()
}
// GOOD
fn process(s: String) -> String {
s.to_uppercase()
}
// OR borrow if you don't need ownership
fn process(s: &str) -> String {
s.to_uppercase()
}
Preallocate Collections
// BAD - many reallocations
let mut vec = Vec::new();
for i in 0..1000 {
vec.push(i);
}
// GOOD - single allocation
let vec: Vec<_> = (0..1000).collect();
// OR with_capacity
let mut vec = Vec::with_capacity(1000);
Zero-Cost Abstractions
Iterators are as fast as loops due to inlining and optimization.
Review Severity
- MAJOR: Unnecessary clones in hot path
- MINOR: Could preallocate collection
- SUGGESTION: Could use iterator instead of loop