|
"Go compiles to native code. Java, ultimately, does too, but compilation happens at runtime, which is an overhead that Go doesn’t have, so in principle Go should be faster." Oh boy. It pains me every time I hear this. In a microbenchmark, JIT compilation increases the time to ramp up to peak performance. Once you're at peak performance, compilation time doesn't matter anymore. At that point, the JIT compiler's drawbacks are mitigated by two distinct advantages. First, the JIT has information about run-time conditions that was unavailable to the static compiler. It's hard to over-state how important it is to know, for example, which if-statements are highly biased, or which polymorphic calls are effectively monomorphic at run time. Second, the JIT can make over-aggressive optimizations based on unverified assumptions, secure in the knowledge that when an assumption proves to be wrong, it can discard that code and re-compile another version of the same method, optimized according to the latest available information. This is only possible if the compiler is present at run-time. [These are my personal opinions, not those of my employer.] |