4 ms·
Everyone posts a comment like this every time undefined behavior surprises someone. But the reality is that the reason why C remains alive is that compiler writ
by pcwalton 9y ago
Everyone posts a comment like this every time undefined behavior surprises someone. But the reality is that the reason why C remains alive is that compiler writers have managed to make it fast. It is not "a couple of percent": these kinds of optimizations can make an enormous difference when, for example, they're the difference between vectorizing a loop and not doing that.
Compiler writers are not "obsessive compulsive". They respond to the demands of their customers. Frequently, the reason why these optimizations exist is that someone filed a bug asking "why doesn't the compiler do this seemingly-obvious optimization?" Often, the only reason these seemingly-obvious optimizations work at all is by exploiting undefined behavior.
- Gibbon1 9y agoC has been pretty fast for basically ever at this point. All these optimizations are just masturbation. Bonus RISC processors are mostly dead at this point having been replaced with pipelined superscalar machines. Which means most of these optimizations are totally pointless. Best comments I've read is one what notes that when you profile modern programs most of the code paths are dead. Yet you have intense hotpots which often turn out to be hand rolled assembly. The second is that you get real speed up carefully choosing your algorithms and memory layout.
- pjmlp 9y agoThe craziness for C optmizer tricks is in many cases plain phsycologic. As an example, it doesn't matter that it does in 5ms what it takes to do in 15ms without the optimization, if in the end anything less than 20ms doesn't have visibile outcome. Actually there is a remark from a famous compiler write (female), which I don't recal the name now, that C brough back into the stone age what the optimizers were already able to do for Algol family of languages. This is visible in PL/8 research paper, a compiler that already used compiler optimization passes in the 70's, nowadays mostly common on LLVM.
- umanwizard 9y agoCan you give some examples of optimization passes in clang/LLVM that you think are unnecessary?
- pjmlp 9y agoI didn't say they aren't necessary, rather that the idea was already used in PL/8 during the 70's, a type safe safe systems programming language. https://courses.physics.illinois.edu/cs426/fa2017/Papers/pl8.auslander.cc82.pdf https://courses.physics.illinois.edu/cs426/fa2017/Papers/pl8... http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.87.4077 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.87.4...
- conistonwater 9y agoCould it be Fran Allen, the one with the Turing award? But I can't find the comment with google, so maybe not.
- pjmlp 9y agoYes it was her. The statement is actually part of the "Coders at Work" interview, where she explains why "how C has grievously wounded the study of computer science." from her point of view. http://www.codersatwork.com/fran-allen.htmlhttp http://www.codersatwork.com/fran-allen.htmlhttp:
- pcwalton 9y ago> As an example, it doesn't matter that it does in 5ms what it takes to do in 15ms without the optimization, if in the end anything less than 20ms doesn't have visibile outcome. That hasn't been true ever since power consumption started mattering.
- pjmlp 9y agoIf it really mattered at that level, people would have already stopped trying to do Web based OS or applications for mobile phones. Also Apple, Google and Microsoft would expose the complete set of mobile and watch OS APIs to C and C++ developers, which they don't. They are kept down to the bare minimum for the upper OS layers.
- Gibbon1 9y agoIf you mean takes 15ms vs 5ms to compile yes. However if you're talking executions speed those low hanging fruit optimizations were picked in the 1980's. What we're talking about here are optimizations that speed up some obscure benchmark on a disused architecture by 5%. Bonus no telling if performance is worse on next years silicon.
- clarry 9y agoSo now the compiler should also statically figure out how long some code is going to take to run? Chances are I want the compiler that gives me a binary that does its job in 2 hours rather than 6.
- iainmerrick 9y agoEveryone posts a comment like this every time undefined behavior surprises someone. Yes! Because it's terrifying, and the explanation is not reassuring.
- deleted 9y ago[deleted]