Premature Optimization
Your code doesn’t work, but you’re spending the majority of your time debating new implementations details in order to achieve maximal performance.
You’re finally deciding to address your longstanding problem of missing deadlines, but there are so many calendar apps out there, and it’s oh-so-hard to decide which one to use. You definitely need to do more research before committing.
You buy a self-help book and really enjoy it. If you could internalize even half of what that book suggested, you could be an entirely different—and better—person. To collect more advice for self-improvement, you decide to buy another self help book. And wow, that one was maybe even better, so you buy another self-help book. Then another. Congratulations, you’re reading more, but otherwise your life hasn’t changed.
New year, new you, and it’s time to start working out. You purchase a gym membership, but decide to put together a detailed workout routine so you can maximize the return for the time you spend in the gym. After all, once you’re at the gym, you might as well do the best that you can, right? Two weeks later, your routine is solidified, but you’ve only been to the gym once. The thought of having to do that full routine again dissuades the idea of returning.
New year, new you, and it’s time to start improving your diet. You’re no dietician, so you decide to do some research into the diet that would suit you best. Mediterranean? Keto? Vegetarian? Vegan? Intermittent fasting? You put together a spreadsheet comparing which foods and eating times are acceptable under all the most popular diets, only to realize you don’t like any preexisting diet and would rather craft your own. You spend a few days doing this. Having crafted your own, you now need to put together a rotating meal schedule based on ten-day cycles because, of course, a seven-day cycle would be far too bland; it would take the fun out of eating, knowing that Tuesday dinner is always fish tacos, and every Friday is grilled chicken wraps; indeed, it’s much better to keep yourself on your toes by making the meal you’ve set for any given day to be hard to remember, regardless of if that comes with a lot more overhead from being completely out of sync with the rest of your life. But it’s now been two weeks, and you haven’t started dieting.
We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%. – Donald Knuth
It may be the case that your code efficiency improvements may have been critical for the program to be fast enough to reasonably use; that your calendar search may have led you to the only calendar app that works for you; that your self-help book binge continued until one book hit home, convincing you to start actually changing instead of merely fantasizing about it; that after you trudged to the gym a few times, your Ultimate Gym Routine was so effective that the changes you expected to see after months happened in weeks, motivating you to keep working out; or that your ten-day cyclical amalgamated diet was just barely enjoyable enough to stick to long-term, and anything less optimized would’ve been a failure from the get-go.
The “critical 3%” do exist, but I wouldn’t bet on them from the start.
“Premature optimisation is the root of all evil” seems, surprisingly, to be a sazen. I believe there’s a chance that wanting to optimise everything is one way people learn the area they’re going to be working in. After this, they might burn out. But then, if and when they come back a second time, they remember from experience that “premature optimisation gets one nowhere”, and actually begin solving the problem. The once prematurely optimised problems become boring to them, so they “just” solve them in a boring and completely adequate way. But they can only prevent themselves from expending effort in optimising problems because they know a. how to solve them optimally, and b. how much it even matters if that problem is solved inadequately.
If you think about the reality where no such premature optimisation occurs, it’s typical to feel like you’re slashing in the dark. “is this the right way to do this? Dear God I hope so!” is how it feels. Eventually when you come across a nugget of vital information, it feels like “wow, I wish I had done some background study first, so I could have been doing this properly the whole time”. When one lacks knowledge about their subject, and what a typical best answer looks like, I feel like they probably can’t come up with “boring” solution to things. They can probably only come up with solutions that feel like “Did I care about this enough? Is this going to be a problem eventually? This seems botched.”
So yeah, you only get to say “premature optimisation is the root of all evil” if you know what wasted premature optimisation feels like, is what I think.
This seems to be people trying to maximize rather than thinking about the area under the curve.
For the gym example, what actually matters is “muscles gained” (or weight loss, or your 1-rep max bench, or whatever), but instead people try to maximize “muscles gained” / gym session.