Well, optimizations need good abstractions to work with. The reason why a SQL query can run much faster than a naive for loop would is precisely due to SQL being very removed from lower-level details.
So in extension, optimization is terrible because we might be using the wrong abstraction level? E.g. it is hard to optimize a larger JS program, because if the developer specified some sort of detail it might throw out an entire class of possible optimizations.
There is actually an interesting presentation on the topic here: https://news.ycombinator.com/item?id=9396950 , which discusses among others whether a two-way communication between compiler and developer may help.
There's been an interesting talk on this a few months ago:
- http://blog.cr.yp.to/20150314-optimizing.html
- (PDF) http://cr.yp.to/talks/2015.04.16/slides-djb-20150416-a4.pdf
Discussions:
- https://news.ycombinator.com/item?id=9202858
- https://news.ycombinator.com/item?id=9396950