Rules
Performance Rules
Rules for detecting performance anti-patterns in Rust code.
excessive-clone
Severity: Warning
Detects .clone() calls on large structs, especially inside loops. Cloning in hot paths can cause significant performance degradation.
// Bad
for item in &items {
let owned = item.clone();
process(owned);
}
// Good
for item in &items {
process(item);
}string-from-literal
Severity: Warning
Detects String::from("literal") which is slower than "literal".to_owned() or "literal".to_string().
// Bad
let s = String::from("hello");
// Good
let s = "hello".to_owned();collect-then-iterate
Severity: Warning
Detects .collect::<Vec<_>>() followed by .iter() or .into_iter(). The intermediate collection is unnecessary.
// Bad
let results: Vec<_> = items.iter().map(transform).collect();
for r in results.iter() { /* ... */ }
// Good
for r in items.iter().map(transform) { /* ... */ }large-enum-variant
Severity: Warning
Detects enum variants where the size difference exceeds 200 bytes. Large variants waste memory for every instance of the enum.
// Bad
enum Message {
Small(u32),
Large([u8; 1024]),
}
// Good
enum Message {
Small(u32),
Large(Box<[u8; 1024]>),
}unnecessary-allocation
Severity: Warning
Detects heap allocations where a stack reference would suffice.