4 ms·
premature optimization is the root of all evil. "I approve too! But… Sometimes it just has to be fast, and sometimes that means the performance has to be desig
by djmips 4y ago
premature optimization is the root of all evil.
"I approve too! But… Sometimes it just has to be fast, and sometimes that means the performance has to be designed in. Nelson agrees and has smart things to say on the subject."
- so... you're saying premature optimization isn't the root of all evil. Maybe it's time to retire this tired 'conventional wisdom'
- dralley 4y agoNot to mention the paragraph that immediately follows the more famous one, in Djiksta's essay: >> Yet we should not pass up our opportunities in that critical 3%. A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified.
- dahart 4y ago> you're saying premature optimization isn't the root of all evil. Maybe it's time to retire this tired 'conventional wisdom' Funny you mention it. I have a bit of a habit now of reminding people what the remainder of Knuth’s quote actually was. “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%.” The irony of walking away with the impression that Knuth was saying to not do optimization is that his point was the exact opposite of that, he was emphasizing the word premature, and then saying we absolutely should optimize, after profiling. This all agrees completely with the article’s takeaways: build it right first, then measure, and then optimize the stuff that you can see is the slowest.
- astrange 4y agoThe 97% does have its own performance opportunities; rather than making it faster you want to stop it from getting in the way of the important stuff, by reducing code size or tendency to stomp on all the caches or things like that. Anyone optimizing via microbenchmarks or wall time exclusively isn’t going to see this.
- doodpants 4y agoNo, they're saying that not all optimization is premature. Or that upfront performance considerations in the design are not necessarily a case of premature optimization.
- jaywalk 4y agoIf you already know that something has to be fast, then it's not really premature optimization.
- trashtester 4y agoI would say, in most cases it pays to make the overall design of the code in a way that enables fast execution. This includes selection of languages and libraries. Identifying loops or recursion with many iterations (high N) with a high Big O order may also be avoided during the design stage, of you KNOW the N and O-order at design time. (And don't worry about the O-order for low N problems, that is premature optimization most of the time.). On the other hand, tweaking every single statement or test in ways that save 1-2 cycles is rarely worth it. Often you end up with obfuscated code that may even make it harder for the compiler to optimize for. This is the 97% of the code where premature optimization makes things harder. Some programmers may turn this on its head. They don't understand the implications of the design choices, but try to make up for that by employing all sorts of tricks (that may or may not provide some small benefit) in the main body of the code.
- deleted 4y ago[deleted]
- runevault 4y agoI hate "premature optimization" so much. The only optimization type I understand that with is very isolated but convoluted fixes that buy performance at the cost of readability/etc. Intelligent architecture that is fast, so long as it is does not completely obfuscate the intent of the code, is not premature.
- bee_rider 4y agoI don't think this follows. If premature optimization is the root of all evil, essentially, we're saying "for all evil, there exists a premature optimization which leads to it." If evil, then sourced in a premature optimization. Even if we parse his "But..." as saying, "there exists some premature optimization which is not the root of an evil" (ignoring probably valid quibbles about whether the optimizations he's talking about truly are premature), this doesn't contradict the original statement. In fact, "the root of all evil" seems to be an expression which invites us to commit the fallacy of denying the antecedent -- if premature optimization, then evil, in this case -- because it is almost always used to indicate that the first thing is bad.