Premature Optimization
Spending effort making code fast before you know where it's actually slow trades clarity for speed you may not need.
Premature Optimization is the practice of tuning code for performance before measurement has shown that performance is actually the constraint, or before you know which part of the system is the constraint. Donald Knuth's line — "premature optimization is the root of all evil" — is usually quoted as a blanket argument against caring about performance early, which overshoots what he actually said: the full sentence advises forgetting about small efficiencies "say about 97% of the time" while never passing up the critical 3% of opportunities — a claim about how often micro-tuning matters, not a case against optimization itself.
The cost isn't just wasted effort on code that turns out not to matter — it's that optimized code is usually harder to read, harder to change, and more tightly coupled to assumptions about the data it runs on than the straightforward version would have been. Manually unrolling a loop, hand-inlining a function, or reaching for a lock-free data structure all trade general-purpose clarity for a specific performance property, and that trade is only worth making where the property is actually needed. Paying it everywhere means every future reader pays the readability tax, for a speed benefit that in most of the codebase nobody will ever notice or measure.
The corrective isn't "never think about performance" — it's sequencing: write the clear version first, profile a realistic workload to find where time is actually spent, and then optimize the specific hot path the profiler points to, backed by a before/after measurement so you know the change actually helped. This is the same discipline Ground Truth argues for generally — a guess about which function is slow is a report, a profiler trace is the measurement — and skipping straight to optimization is a form of the Streetlight Effect, tuning the part of the code that's easiest to reason about rather than the part the data says is actually costly.
The rule has a real boundary, worth stating so it doesn't get taken as absolute: some decisions are far cheaper to make well upfront than to retrofit later — a database schema, a public API's shape, an algorithm with quadratic behavior on inputs you already know will be large. Premature optimization is about micro-tuning ahead of evidence, not about ignoring an architectural choice whose cost is already knowable without a profiler.
See also6
Big-O Notation
A coarse language for how an algorithm's cost grows as its input grows.
Computation & Algorithms21 connections
Overfitting
A model that fits its training data too well has memorized noise instead of learning the pattern that generalizes.
Method11 connections
Technical Debt
The future cost of a present shortcut, metaphorically accruing interest.
Method31 connections
Benchmarking
Measuring how fast code runs under controlled conditions, which is far harder to do honestly than it looks.
Testing & Verification12 connections
KISS Principle
The engineering maxim that designs should be as simple as the job allows, because simple systems are easier to build, understand, repair, and trust, with the hard part being which complexity can actually be removed.
Method6 connections
Refactoring
Changing the structure of code without changing what it does, in small verified steps, so that the next change becomes easy.
Method11 connections
Linked from6
- BenchmarkingTesting & Verification
Measuring how fast code runs under controlled conditions, which is far harder to do honestly than it looks.
- KISS PrincipleMethod
The engineering maxim that designs should be as simple as the job allows, because simple systems are easier to build, understand, repair, and trust, with the hard part being which complexity can actually be removed.
- RefactoringMethod
Changing the structure of code without changing what it does, in small verified steps, so that the next change becomes easy.
- Technical DebtMethod
The future cost of a present shortcut, metaphorically accruing interest.
- Theory of ConstraintsMethod
Eliyahu Goldratt's management idea that every system's output is limited by a single bottleneck, so improving anything else is wasted until the constraint itself is found, exploited, and raised.
- Virtual ScrollingWeb Platform
Rendering only the rows of a long list that are on screen and recycling them as the user scrolls, so a list of a million items costs about as much to display as a list of thirty.