// Analyzes Rust code for performance bottlenecks, memory inefficiencies, and optimization opportunities. Use when discussing performance, slow code, memory usage, profiling, benchmarks, or optimization.
| name | rust-performance-analyzer |
| description | Analyzes Rust code for performance bottlenecks, memory inefficiencies, and optimization opportunities. Use when discussing performance, slow code, memory usage, profiling, benchmarks, or optimization. |
Expert skill for analyzing and optimizing Rust application performance.
Activate this skill when the user:
Look for:
Vec::new(), String::new() in loops).clone() where borrow would work)Check:
#[repr(C)] where neededEvaluate:
Mutex, RwLock usage)Focus on:
// Bad: Allocates on every call
fn process(items: &[Item]) -> Vec<ProcessedItem> {
items.iter().map(|i| process_one(i)).collect()
}
// Good: Reuse buffer
fn process_into(items: &[Item], buffer: &mut Vec<ProcessedItem>) {
buffer.clear();
buffer.extend(items.iter().map(|i| process_one(i)));
}
// Bad: Unnecessary clone
let data = self.data.clone();
process(&data);
// Good: Borrow directly
process(&self.data);
// Use RefCell/Cell for single-threaded
// Use parking_lot::{Mutex, RwLock} for multi-threaded
// Use atomics for simple counters/flags
# Build with debug symbols
cargo build --release
# CPU profiling (requires cargo-flamegraph)
cargo flamegraph --example <name>
# Memory profiling
RUSTFLAGS="-Z sanitizer=address" cargo +nightly run --example <name>
# Benchmarking
cargo bench
Provide: