Performance Anti-Patterns¶
Learning Objectives¶
- Identify frequent performance anti-patterns.
- Replace inefficient patterns with practical alternatives.
- Measure improvements objectively.
Common Anti-Patterns¶
- Nested loops for repeated lookups.
- Recomputing same expensive values inside loops.
- Excessive object creation in hot code paths.
- Using unsuitable data structures for access pattern.
Better Alternatives¶
- Use hash-based lookup for membership checks.
- Cache repeated computation results.
- Batch operations where possible.
- Move constant work outside loops.
Practice Tasks¶
- Find one O(n^2) routine and optimize it.
- Benchmark before and after optimization.
- Document runtime and memory trade-offs.
Summary¶
Optimize based on bottlenecks, not assumptions.