🎯 Chapter Insight
When developers think about performance, the first instinct is often to optimize code. We tweak loops, cache values, reduce allocations, or rewrite a function in a more efficient way.
But the biggest performance improvements rarely come from micro optimizations.
They come from choosing a better algorithm.
A well chosen algorithm can improve performance by orders of magnitude, while clever implementation tricks often provide only marginal gains. An
O(n log n)
solution will almost always outperform an
O(n²)
solution, regardless of how carefully the slower one is optimized.
Pragmatic developers understand that performance starts with design. Before making code faster, they make sure they are solving the problem the right way.
💡 Developer Lens
In everyday engineering, performance bottlenecks often have little to do with individual lines of code.
Consider a few common examples:
- Replacing a linear search with a hash lookup
- Choosing a
Setinstead of repeatedly scanning aList - Sorting data once instead of repeatedly searching unsorted collections
- Moving expensive work outside a frequently executed loop
- Selecting a more appropriate data structure for the workload
These kinds of decisions can reduce execution time dramatically without making the code more complicated.
The opposite is also true.
Many teams spend hours optimizing code that contributes almost nothing to overall runtime. They optimize because something looks inefficient, not because they know it is the bottleneck.
Pragmatic developers resist this temptation. They measure first. They profile the application. They understand where time is actually being spent before deciding what deserves optimization.
The fastest code is often the code you never needed to execute in the first place.
🧭 Reflection
Think about your recent optimization efforts.
How often did you improve implementation details before questioning the algorithm itself?
Have you ever spent hours making code ten percent faster when a different approach could have made it one hundred times faster?
Are you measuring performance, or guessing?
Good engineering starts with understanding the problem before improving the solution.
⚙️ Practical Tip
The next time you investigate a performance issue, change your approach.
Before writing a single optimization:
- Profile the application
- Find the actual bottleneck
- Examine the algorithm being used
- Consider whether a different data structure would simplify the problem
Only after understanding the real cause should you optimize the implementation.
The biggest performance gains usually come from better design, not faster code.
🔢 #39 of 53 | The Pragmatic Programmer Series
This post is part of my 53-week series summarizing The Pragmatic Programmer, one timeless principle each week, translated into modern software practice and reflection.








