Prompt
Always validate performance changes through profiling or benchmarking before implementation, and favor memory-efficient patterns when making optimizations. Key practices:
- Profile before/after significant changes:
// Before changing buffer sizes, validate impact: const SCROLLBACK_LEN: usize = 1024; // Profile current performance // Test new value const SCROLLBACK_LEN: usize = 2048; // Validate no significant regression - Use memory-efficient patterns:
- Prefer
&strover&Stringto avoid double indirection - Initialize collections with capacity when size is known:
let mut map = HashMap::with_capacity(items.len()); - Return iterators instead of collecting vectors when possible:
// Instead of pub fn get_items(&self) -> Vec<String> { self.items.iter().map(|i| i.to_string()).collect() } // Prefer pub fn get_items(&self) -> impl Iterator<Item = &str> + '_ { self.items.iter().map(|i| i.as_str()) }
- Prefer
- Document performance-critical decisions with benchmarks or profiling results to justify changes.