TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Stop Misquoting Donald Knuth

131 pointsby franzbabout 10 years ago

17 comments

davidtgoldblattabout 10 years ago
The longer I work on performance teams, the more I agree with the &quot;performance always matters&quot; point of view[1]. In large binaries (or at least, in the large binaries I&#x27;ve worked on), we don&#x27;t see a few tight loops taking the bulk of the time. Instead, there&#x27;s a death by a thousand cuts in which many small inefficiencies add up, and have to be clawed back slowly and painfully, often by people with less understanding of the semantics of the code in question than the original authors. Most performance work I see isn&#x27;t stuff like &quot;write the tight loop in assembly; save 30% on execution time&quot;, it&#x27;s stuff like &quot;reuse the locale object to avoid construction penalties; save 0.4%&quot;.<p>For reasons like this I&#x27;m skeptical of e.g. python advocates who say the speed difference doesn&#x27;t matter since you can always rewrite &quot;the hot code&quot; in C. That works when you&#x27;re truly using python as a scripting language; the glue that ties you matrix multiplication routines or whatever together. But when you&#x27;re going to have a large, flat, performance profile, you&#x27;re better off just writing your program in C++ (or its friends) to begin with.<p>[1] So I suppose, you can take this entire comment as &quot;person in specialty thinks everyone else should change to make his life easier&quot;. Maybe I just have a warped view of priorities.
评论 #9460935 未加载
评论 #9460818 未加载
carsongrossabout 10 years ago
<i>” We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.”</i><p>As I&#x27;ve gotten older, I&#x27;ve developed the following interpretation of this statement:<p>Getting system architecture right is hard, but crucial. When it is right, there is very little code to it, as little as necessary for the job. Rather than sprinting ahead and micro-optimizing your initial architecture, you should go slow, focus on minimal-viable units within the system and then, once contact with the real world has occurred, step back and ask if your architecture is going with the problem, akido style, or fighting it, J2EE style. Then, and only then, consider the perf fixes appropriate to whichever situation you find yourself in.
评论 #9460692 未加载
nostrademonsabout 10 years ago
The author is very welcome to start a company that builds software according to these principles. In some domains (databases, network stacks, middleware), he could probably make a killing. In other domains (say, social web applications), he&#x27;d get clobbered.<p>I think this is the problem with appeals to professional ethics. Software is not one profession, and not one industry. It&#x27;s labeled as such because the software industry changes much more quickly than the job categorization industry does. Nowadays, there&#x27;s a huge difference between people who write software that helps planes stay in the air vs. those who let you search the web vs. those who write critical storage infrastructure for other companies vs. those who write software that lets you throw sheep at your friends vs. those who let you order from the grocery store with your phone. The best practices and rules of thumb for one industry don&#x27;t transfer over to another industry. And it&#x27;s not fair to consumers to make them deal with blindingly fast software that doesn&#x27;t actually do what they want when they&#x27;re quite willing to put up with slow, bloated software that does.
评论 #9461041 未加载
评论 #9461326 未加载
andrepdabout 10 years ago
I couldn&#x27;t agree more. It&#x27;s rather alarming really, the mindset that most of the professional developers have on this matter. Making the life of the developer easier is the highest objective, low-level is derided, ease of use for the dev is readily bought with inefficiency, massive layers of abstraction and inefficiency and bloat are <i>everywhere</i>, and above all performance in the end product is sacrificed for the convenience of the developer.<p>Now, I&#x27;m not saying to spend substantial amounts of time and money chasing small micro-optimizations. I&#x27;m saying it makes me think for a while that it seems like everybody just simply <i>stopped giving a shit about performance</i>, and then we end up with orders of magnitude of crud on our software.
评论 #9461442 未加载
评论 #9464057 未加载
mikeashabout 10 years ago
I thought it was a bit silly until I saw that he&#x27;s talking about C++.<p>The smart-everything, RAII-everything approach that most C++ uses these days tends to make everything a little bit slow. In other languages, there&#x27;s usually a small number of places that are slow, and everything else is inconsequential. In C++ you end up spending a lot of time spread among a million different bits of code twiddling smart pointers and RAIIing things that don&#x27;t really need it.<p>I completely lost it at this paragraph, though:<p>&quot;If you tell yourself, <i>it’s only a malloc, it’s nothing</i>, and you do this often enough, you will end up with 25000 temporary allocs for a single keystroke. They may only take 50ns each, but I type 529 characters per minute.&quot;<p>That works out to 1.1% CPU utilization when typing at full bore. (50ns * 25000 * 529&#x2F;minute = 0.011.) In the abstract, that&#x27;s high. But in a practical sense, it&#x27;s completely irrelevant.<p>Shaving CPU cycles off the keystroke handler of an app that only uses 1% CPU in the hands of a fast typist is a massive waste of the programmer&#x27;s time. This paragraph is followed by:<p>&quot;When these sorts of things are pointed out, people aught to respond by fixing the problem, so that they can deliver a better product. Instead, they typically start arguing with you about why it’s not that big a deal.&quot;<p>Well yes, because it&#x27;s <i>not</i> that big of a deal. There are better places to spend your time. A product that uses 0.01% CPU while typing at full bore is not noticeably better than one that uses 1% CPU. You won&#x27;t &quot;deliver a better product&quot; by addressing this, you&#x27;ll waste a bunch of time you could have spent building a product that&#x27;s actually better.
评论 #9461403 未加载
jkoudysabout 10 years ago
I&#x27;m glad this article exists, mainly because calling any and all optimization work a &quot;micro-optimization&quot; has become highly fashionable among the lazy. For every 1 developer who actually understands what Knuth was saying, there are 5 more who think that concern for performance during implementation is &quot;premature&quot;, and will take any opportunity to criticize others, loudly, so that they appear intelligent.<p>I recently had someone chastise me for micro-optimising, before even seeing the code, understanding the use-case, or knowing that my load-tests already established this as a bottleneck. I&#x27;d barely said more than &quot;I&#x27;m looking for a more efficient implementation of this&quot; before being shamed as a micro-optimizer. It&#x27;s out of control.
aleccoabout 10 years ago
They keep telling you:<p>&gt; &quot;We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.<p>But they always omit the following part of the quote:<p>&gt; 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
评论 #9460859 未加载
kenjacksonabout 10 years ago
The key part of the quote is the word &quot;premature&quot;. Optimization is important, but you need to be optimizing the code that matters.
ameliusabout 10 years ago
&gt; There is a whole class of developer out there who rejects any optimization beyond occasional attention to asymptotic complexity. They believe that their responsibility ends once they’ve picked the theoretical best algorithm, and that at this point things are as good as they’re likely to get.<p>And there&#x27;s also a whole class of developers that don&#x27;t seem to care about asymptotic complexity. Take for example the React crowd: in React, in its rawest form, every little update to the DOM will require O(N) time to update the display, even though the update is usually fast because of the diffing algorithm. However, the O(N) complexity puts a strong limit on the maximum complexity of the DOM tree, and it is imprudent to just ignore that.
评论 #9465382 未加载
nedumaabout 10 years ago
Couple of quotes comes to mind related to abstraction.<p><pre><code> Premature Optimization is like fart: Premature Abstraction is like a taking dump in another developer desk </code></pre> More less blunt version of that<p><pre><code> Premature optimization, that&#x27;s like a sneeze. Premature abstraction is like ebola; it makes my eyes bleed.</code></pre>
Houshalterabout 10 years ago
One example is Skype on Windows. It now takes several minutes to load when it used to be a few seconds. Also I find mobile hard to use for everything because there are 10 second delays between every trivial task you want to do and it adds up.
nailerabout 10 years ago
Knuth:<p>&gt; The conventional wisdom shared by many of today’s software engineers calls for ignoring efficiency in the small; but I believe this is simply an overreaction to the abuses they see being practiced by penny-wise- and-pound-foolish programmers, who can’t debug or maintain their “optimized” programs<p>I think ignoring efficiency is bad, but ignoring efficiency is very different to not prematurely optimising. The author seems to be misquoting Knuth to a certain extent by equating them.<p>Give me the fast enough, no performance issues, no repetition maintainable code with those intermediary variables please.
zinxqabout 10 years ago
&quot;premature optimization&quot; is statement setting itself up for negativity. Of course &quot;premature&quot; optimization is bad - so is basically anything else that happens prematurely.<p>That&#x27;s not to deny thoughtful optimization when logical, even before the program runs. I&#x27;ve often found Knuth&#x27;s quote to be interpreted as &quot;Performance doesn&#x27;t matter - just get it to run&quot;.<p>Which as Knuth points out, for &quot;one shot&quot; programs is probably fine, but for anything in the longer term is damaging.
busterabout 10 years ago
Totally agree. I always read &quot;but memory and CPU is not a concern&quot; and i can cry.
devyabout 10 years ago
I would really love to hear if Mr. Donald Knuth could reclarify his quote 40 years later again.
评论 #9460787 未加载
sinwaveabout 10 years ago
May I please have your faster than nlogn sorting algorithm
评论 #9460982 未加载
评论 #9460999 未加载
评论 #9461229 未加载
评论 #9464584 未加载
mhurronabout 10 years ago
&quot;No.&quot; -Donald Knuth<p>Edit: Now, now, I&#x27;m pretty sure he has said that at least once in his life.