Why is Java faster when using a JIT vs. compiling to machine code?

前端 未结 10 1677
轻奢々
轻奢々 2020-12-12 12:27

I have heard that Java must use a JIT to be fast. This makes perfect sense when comparing to interpretation, but why can\'t someone make an ahead-of-time compiler that gener

10条回答
  •  醉酒成梦
    2020-12-12 13:23

    A JIT compiler can be faster because the machine code is being generated on the exact machine that it will also execute on. This means that the JIT has the best possible information available to it to emit optimized code.

    If you pre-compile bytecode into machine code, the compiler cannot optimize for the target machine(s), only the build machine.

提交回复
热议问题