Compiler Performance and LLVM
pling.jondgoodwin.com
pling.jondgoodwin.com
[1]: https://github.com/CraneStation/cranelift
[2]: https://cranelift.readthedocs.io/en/latest/compare-llvm.html
These compilers are mainly designed for extreme performance. People complaining slow compilation of LLVM must never used ICC's -fast mode before, where a helloworld can take ~30s to compile. Developers still spend thousands on it because it squashed every drop of performance.
The problem is having both at the same time (i haven't seen any build configuration try to mix optimization levels) without compromising on compiler speed for -O1, so projects that require -O2 for a 0.1% of their codebase apply it for 100% of it.
In theory depending on the language you could mix different compilers, but that is a big can of worms (and other bugs).
In other words, it is not "hard" to build compilers with better performance. What is hard is getting performance without build times exploding.
The post made me look into string interning for my compiler. I wasn't convinced that it would be that useful. I thought that most unsuccessful string comparisons are fast anyways, because I store the length for each token. With a hash map, you still have to do one comparison for every lookup, and you also have to compute the hash. But it also greatly increases the odds that it's the right comparison. And once you did the interning, you don't need to look up strings anymore at all.
I (very sloppily) implemented a hash map, and integrated it into the lexer. Despite the poor implementation, and having to build the map in the lexer, it does speed up the check whether an identifier is a keyword, and reduced the parse time to about 70%. I get similar gains for code generation, because it speeds up the symbol lookup, but it's probably going to be less useful here, since I still have terrible O(n) lookup for globals. The absolute gains are still worth it, though.
So yeah. Thanks for encouraging me to look into it!
As for you questions about performance on bigger source files and twiddling optimization options, I too am curious about that. I will likely revisit those questions at some point in the future. It will be easier to do once I have baked these diagnostics into the compiler.