Premature Optimization
The practice of trying to improve code performance before it's necessary, often at the expense of clarity and maintainability.
Also known as: Early Optimization, Speculative Optimization
Category: Software Development
Tags: software-engineering, performance, programming, best-practices, anti-patterns
Explanation
Premature Optimization refers to the practice of trying to make code faster or more efficient before it's been demonstrated to be a bottleneck. Donald Knuth famously stated: 'Premature optimization is the root of all evil.' The problem isn't optimization itself, but optimizing the wrong things at the wrong time. Key issues include: (1) Wasted effort - most code isn't performance-critical, (2) Reduced readability - optimized code is often harder to understand, (3) Introduced bugs - complex optimizations create new failure modes, (4) Wrong targets - developers often guess wrong about bottlenecks. The better approach is: write clear code first, measure performance, identify actual bottlenecks through profiling, then optimize only what matters. The 80/20 rule applies—typically 20% of code causes 80% of performance issues.
Related Concepts
← Back to all concepts