【Compilation】JIT&AOT introduction and advantages and disadvantages


AOT introduced this feature in .NET 7 released last year, only to be further improved in .NET 8. The "Hello, World" application published through Native AOT in the new version is further reduced in size, only half of .NET 7.

Taking CoreCLR as an example, the asp.net core website project that does not do AOT compilation usually takes about 150ms for cold startup, but as the program runs after startup, JIT will generate better code again, even for frequently used generic classes Specialize a set of implementations; after the ReadyToRun technology compiles and initializes the part, the JIT can be preserved, and at the same time, the program initialization part is accelerated by AOT technology, reducing the startup time to about 80ms; the last is pure AOT, which is compiled by CoreRT and started The speed can directly reach below 10ms.

Among AWS's FaaS services, .NET Core's function computing service uses technologies such as ReadyToRun/CoreRT, making its startup speed the champion.

However, the memory footprint of .NET Core itself is very small, and the memory footprint advantage brought by AOT compilation is almost negligible. However, Full AOT makes it impossible to realize many advanced features, such as the dynamic generation of IL by expression trees. For .NET Core, the advantages of AOT over JIT are not obvious except for smaller programs.

As for Java/JVM, there must be AOT technology. Compared with the original JIT solution, I think it should be able to improve greatly in terms of startup speed and memory usage, because the current Java startup speed and memory usage are really unbearable. look straight at.
insert image description here

JIT

JIT, that is, Just-in-time, dynamic (just-in-time) compilation, compiling while running;

excellent

  1. It can compile and generate optimal machine instructions in real time according to the current hardware conditions (ps. AOT can also be done, and the user uses bytecode to compile once according to the machine conditions)
  2. The optimal machine instruction sequence can be generated according to the running conditions of the current program
  3. When the program needs to support dynamic linking, only JIT can be used
  4. The code can be adjusted according to the actual situation of the memory in the process, so that the memory can be more fully utilized

High throughput, with runtime performance bonus, can run faster, and can dynamically generate code

inferior

  1. Compilation needs to occupy runtime resources, which will cause the process to freeze
  2. Since the compilation time needs to occupy the running time, the compilation optimization of some codes cannot be fully supported, and a trade-off needs to be made between the smoothness of the program and the compilation time
  3. Time spent preparing for compilation and identifying frequently used methods prevents initial compilation from achieving peak performance

The relative startup speed is relatively slow, and it takes a certain amount of time and calling frequency to trigger the JIT layering mechanism

AOT

AOT, Ahead Of Time, refers to compiling before running

excellent

  1. Compile before the program runs to avoid compilation performance consumption and memory consumption at runtime
  2. Can achieve the highest performance in the early stage of program operation
  3. Can significantly speed up program startup

Low memory footprint, fast startup, can run without runtime, and directly statically link the runtime to the final program

inferior

  1. Compiling before the program runs will increase the installation time of the program
  2. Sacrifice Java Consistency
  3. Saving pre-compiled content will take up more memory

There is no runtime performance bonus, and no further optimization can be made according to the running conditions of the program

difference between the two

The main difference between these two compilation methods is whether to compile at "runtime"

source

Comparing JIT and AOT, what are the advantages and disadvantages of each?
The difference between AOT and JIT, their respective advantages and disadvantages, mixed compilation

Guess you like

Origin blog.csdn.net/weixin_44231544/article/details/130240765