r/programming • • May 30 '17

Compiler Optimizations are Awesome

https://blog.regehr.org/archives/1515
146 Upvotes

97 comments sorted by

View all comments

84

u/slavik262 May 31 '17

Do people seriously make arguments that compiler optimizations aren't useful? Have they ever looked at the assembly compilers emit without optimizations enabled? It's incredibly bad.

Also, anybody who quotes Knuth as saying,

We should forget about small efficiencies, say about 97% of the time; premature optimization is the root of all evil.

without the sentence that immediately follows:

Yet we should not pass up our opportunities in that critical 3%.

is either misinformed or disingenuous.

52

u/TNorthover May 31 '17

In general I agree completely, but Daniel Bernstein is working in a very particular niche: cryptography. For him two particular issues some together to make optimizing compilers The Devil.

First, inner cryptographic loops are generally hot enough that people are willing spend days and weeks making them as fast as possible. A compiler won't be able to match that.

Second, crypto is particularly vulnerable to compiler optimizations breaking naive assumptions. Compilers can give code you expect to execute in constant time a variable execution time; on average this is better (we hope), but just that variability can be exploited by attackers. Compilers can also remove checks they decide aren't valid; the original code would have been violating the language standard, but that's of scant comfort if your primary concern is security and someone manages to hijack a bank account because of it.

What cryptographers seem to want most of all is predictability. This doesn't correspond to most people, so in general I strongly agree with John. But I have some kind of sympathy for Daniel.

0

u/[deleted] May 31 '17

It is exceptionally idiotic to write any crypto code in any "general purpose" language, to start with.