4 ms·
"much hand-optimized 90s-era C code is now slower than more naive implementations, because the optimizations used to save some instructions often actively harm
by mfukar 16y ago
"much hand-optimized 90s-era C code is now slower than more naive implementations, because the optimizations used to save some instructions often actively harm cache performance."
On the same hardware? That seems unlikely - do you have a specific example in mind?
- a-priori 16y agoHe means that the hardware has changed. Micro-optimization these days mostly has to do with optimizing cache and memory I/O performance rather than reducing clock cycles as it was in the 90s.
- btilly 16y agoYes. On the same hardware. And I'm sure that a specific example was thought of. To give one of several likely causes, CPU pipelines have grown much longer. As a result it is more important to avoid stalls these days. Naive code compiled with a modern compiler knows about the importance of this. For instance the compiler will know it can avoid a stall in certain cases by making sure that a read from memory that happens soon after a write obeys something called store to load forwarding restrictions. Doing that can mean extra code which would be slower on an old computer, but it is faster than a modern one.
- mfukar 16y agoWell, if we're talking about different hardware, this whole discussion is moot - CPU (not C-entral anymore..) architecture changes render "old" optimization techniques only situational today. At any rate, the same is true for all languages, and _delirium's point is spot on: it's not the language that matters, it's the fact that bad (or slow, or inefficient, call it what you will) code is encountered regardless. It's time we stopped language wars, don't you think?
- JoeAltmaier 16y agoAgreed. Its like my yellow framing hammer; useful for one job, but I have other hammers. (said this before)
- btilly 16y agoThe discussion is only moot to the extent that the complaint is inaccurate. It is true that code, once optimized, is frequently hard to unoptimize. It is further true that what you optimize for at one point does not match what you optimize for at another. It is also true that there is a lot of C that is now optimized for the wrong thing. And finally it is true that people who write C because they are trying to squeeze performance are more generally prone to create more of it. As long as those facts remain true, it is fair to complain about this tendency in C code in the wild. Even though the problem clearly lies with some of the programmers the language attracts rather than with the language.
- mfukar 16y agoAnd finally it is true that people who write C because they are trying to squeeze performance are more generally prone to create more of it. You can't imply "fact" and use "generally" in the same sentence, sorry.