AOT, JIT, IL2CPP, Mono in unity

1. What are JIT and AOT?

JIT, Just-in-time, dynamic (just-in-time) compilation, compiling while running; AOT, Ahead Of Time, refers to compiling before running, which are two ways of compiling programs

Two, pros and cons

Advantages of JIT:

① 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) ② It can generate optimal machine instructions according to the current program running
conditions Machine instruction sequence
③ When the program needs to support dynamic linking, only JIT can be used
④ 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

Disadvantages of JIT:

①Compilation needs to occupy runtime resources, which will cause the process to freeze.
②Because the compilation time needs to occupy runtime, the compilation optimization of some codes cannot be fully supported, and a trade-off needs to be made between program smoothness and compilation time.
③In compilation preparation and identification Frequently used methods take time, preventing initial compilation from achieving maximum performance

Advantages of AOT:

① Compile before the program runs, which can avoid the compilation performance consumption and memory consumption at runtime
② Can achieve the highest performance in the early stage of program running
③ Can significantly speed up the startup of the program

AOT disadvantages:

①Compiling before the program runs will increase the installation time of the program
②Sacrificing the consistency of Java
③Saving the content compiled in advance will take up more external resources

Three, associated with unity

1. JIT & Mono compilation

Unity's cross-platform technology is realized through a Mono virtual machine. And this virtual machine is too slow to update and cannot be well adapted to many platforms.
Mono compilation process

Android will generate:
\assets\bin\Data\Managed\ Assembly-CSharp.dll (control logic of the game, called at runtime)

\lib\armeabi-v7a\ libmono.so, libmain.so, libunity.so (libmono.so will complete the function of mono VM)

2. AOT & IL2CPP compilation

Unity company has developed IL2cpp by itself, which converts the intermediate code that should have been run on the mono virtual machine into cpp code, and then uses the cross-platform feature of c++ to convert the generated cpp code on each platform to each platform
. Compiled with a well-optimized native c++ compiler for higher efficiency and better compatibility.
What is a native compiler? What is a cross compiler?
ILL2CPP compilation process

Android will generate:
\assets\bin\Data\Managed\ Assembly-CSharp.dll is generally not packaged into the apk (the control logic of the game is only stored as an intermediate file and will not be called during runtime)

\lib\armeabi-v7a\ libil2cpp.so, libmain.so, libunity.so (libil2cpp.so contains native code for game control, and IL2CPP VM function)

3. Advantages of IL2CPP over Mono

①Mono VM is transplanted on various platforms, maintenance is very time-consuming, and sometimes it is impossible to complete
②Mono version authorization is limited
③Improve operating efficiency
④With IL2CPP, the program size can be relatively reduced and the operating speed can be increased!
⑤Compared with Mono in terms of heap memory allocation using IL2CPP, Reserved Total can be reduced, while Mono's Reserved Total will only increase and not decrease.

Related link: https://blog.csdn.net/h1130189083/article/details/78302502
Related link: https://www.cnblogs.com/eniac1946/p/7417191.html
Related link: https://zhuanlan.zhihu .com/p/19972689

Guess you like

Origin blog.csdn.net/cgExplorer/article/details/107029630