5 ms·
The focus on Go compiler speed is kinda weird to me. Other languages sometimes offer flexible tradeoffs to developers. You can build and test C++ programs fair
by shereadsthenews 7y ago
The focus on Go compiler speed is kinda weird to me. Other languages sometimes offer flexible tradeoffs to developers. You can build and test C++ programs fairly quickly if all the optimizations are disabled, or you can spend a long time building a release binary with optimization, load-testing, profile-guided recompilation, link-time optimization, and post-link optimization. But Go only offers the first thing: a fast compiler with almost no optimizations.
- sagichmal 7y agoThe Go compiler contains lots of optimizations, especially considering its age.
- limxto0 7y agoCan you share some more details about what those optimizations are? Can you point us to a link?
- foldr 7y agohttps://quasilyte.dev/blog/post/go_ssa_rules/ https://quasilyte.dev/blog/post/go_ssa_rules/ is maybe a good starting point.
- __HYde 7y agoYou could try compiling with and without `-gcflags '-N -l'` `-N` disables optimization and `-l` disables in-lining. I also found this[0] page which lists some optimizations done by the compiler. [0] https://github.com/golang/go/wiki/CompilerOptimizations https://github.com/golang/go/wiki/CompilerOptimizations edit: You can see what the compiler emits as assembly code with `-gcflags '-S'` so you can compare the optimized vs unoptimized assembly.
- The_rationalist 7y agogo is indeed slow, cd benchmarkgames website
- bluGill 7y agoC++ with all optimizations disabled is still slow. g++ takes 2.8 seconds to compile a simple helloworld on my machine - or .14 seconds the second time after caches are warm... Python2 can build and run helloworld in .028 seconds, or .011 once caches are warm. Of course the C++ hello world runs in .002 seconds once build (caches don't seem to make a difference but that might be because it was still in the cache from building)
- dman 7y agoWhat version of gcc? What OS? I am showing ~0.4 seconds on a machine that is 3-4 years old. [PS: I think even 0.4 seconds is too slow]
- jandrese 7y agoC++'s templates (code!) in headers can cause a lot of pain on the compilation front. A simple #include <boost> can add many seconds to your compile.
- danbolt 7y agoRecently at work I was able to use C++ templates to automate a lot of repeated boilerplate code I was responsible for. The reason was to minimize the amount of (error-prone!) rote work that had to be done as the project would continue to scale. It worked out great, but I’ve noticed that the compilation time of translation units that use the templates have been growing linearly with features added. It’s not a lot in the big scheme of things, but it made me wish I could reason more about C++ compile times when I use its various features.