<skill_overview> Keep Rust code fast while staying idiomatic
Optimizing hot loops Reducing allocations Choosing data structures Measuring performance impact
The Rust Book - Performance
</skill_overview> <zero_cost_abstractions>
Use iterators and closures freely; they compile to efficient code Prefer expressive, safe code and measure before micro-optimizing
</zero_cost_abstractions>
Prefer borrowing (&str, &[T]) over allocating (String, Vec) Pre-allocate with Vec::with_capacity when size is known Avoid unnecessary clones; pass references where possible
let mut buf = Vec::with_capacity(1024);
<hot_paths>
Avoid repeated formatting or allocation in tight loops Reuse buffers and temporary values when possible
</hot_paths>
Benchmark with realistic data sizes Compare before and after changes
<anti_patterns> Optimizing before profiling Cloning on each iteration Growing collections without bounds </anti_patterns>