This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3162|Reply: 1

[Communication] Introduction and difference between JIT and AOT compilation in .NET

[Copy link]
Posted on 2/15/2024 5:17:46 PM | | | |
Terminology

CLI: Common Language Infrastructure is a specification under the .NET framework that defines a language-agnostic, cross-architecture runtime. Therefore, we can develop software in various high-level languages under the specification that can run in different computer architectures without modification

CLR: Common Language Runtime. is a specification that ensures that the operating environment is language-independent and cross-architectural

CTS: Common Type System

CLS: Common Language Specification

FCL: Framework Class Library 架构类库,包含两部分: 基础类库 Base Class  Library 和成品类库

IL: Immediate Language Intermediate Language, Advanced Language Compiler compiles the source code of advanced languages into intermediate languages.

JIT: Just In Time Compiler compiles an intermediate language into machine code that a computer can understand, which can then be executed

Source Code is compiled into IL by C# Compiler (i.e., programs, dlls, exes, etc.). The CLR loads these ILs, compiles them into machine code through JIT, and is finally executed, as shown in the following figure:



JIT (Just-in-time compiler) is compiled on the fly

The just-in-time compiler (JIT) is part of the Common Language Runtime (CLR) in .NET and is responsible for managing the . .NET program, regardless of any . .NET programming language. Language-specific compilers convert source code to intermediate languages. This intermediate language is then converted into machine code by an just-in-time (JIT) compiler. This machine code is specific to the computer environment in which the JIT compiler runs.  JIT Compiler Work: JIT compilers need to speed up code execution and provide support for multiple platforms. Here's how it works:



The JIT compiler converts Microsoft Intermediate Language (MSIL) or Common Intermediate Language (CIL) into machine code. This is done before performing MSIL or CIL. MSIL is converted to machine code as needed, i.e., the JIT compiler compiles MSIL or CIL as needed, rather than compiling the entire code. Store the compiled MSIL or CIL so that it can be used for subsequent calls if needed.

JIT Pros:

  • It can be compiled and generated in real time according to the current hardware situation
  • The optimal machine instruction sequence can be generated according to the current program operation
  • When a program needs to support dynamic linking, it can only use the JIT compilation method
  • The code can be adjusted according to the actual situation of memory in the process to make better use of memory


JIT Cons:

  • Compiling requires the resources of the runtime runtime, which causes the process to stutter when executing
  • Compilation takes up running time, and some code compilation optimizations cannot be fully supported, so it is necessary to balance fluency and time
  • Compilation preparation and identification of frequently used methods are time-consuming, and the initial compilation does not achieve the highest performance


AOT (Ahead-of-time compiler) is compiled in advance

In computer science, early compilation (AOT compilation) is the act of compiling a (usually) high-level programming language into a (usually) low-level language before executing a program, usually at build time, to reduce the amount of effort that needs to be performed at runtime.

Most of the time, it is not the same as combining high-level programming languages (such as C or C++) or intermediate representations such as Java bytecode or . NET Framework Common Intermediate Language (CIL) code) compiled to be native (system-dependent) behavior-related. machine code so that the resulting binaries can be executed natively, just like a standard native compiler. When used in this specific environment, it is often seen as the antithesis of just-in-time (JIT) compilation.

AOT compilation occurs before the program is compiled or installed, that is, it precompiles scripts or bytecodes into machine code and executes them directly when needed. This can improve program startup speed and avoid delays caused by the compilation process.

AOT Pros:

  • Compiling before the program runs avoids compilation performance and memory consumption at runtime
  • Peak performance can be achieved early in the program
  • It can significantly speed up the efficiency of program execution


AOT Cons:

  • Compiling before the program runs increases the time it takes to install the program
  • Saving pre-compiled content takes up more memory
  • Sacrificing the consistency of high-level languages


summary

JIT: High throughput, runtime performance bonus, can run faster, and can dynamically generate code, etc., but it is relatively slow to start and requires a certain amount of time and call frequency to trigger the JIT layering mechanism
AOT: Low memory usage, fast startup speed, can directly link the runtime statically to the final program without runtime, but there is no runtime performance bonus, and it cannot be further optimized according to the running of the program



Reference:

The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.





Previous:.NET/C# High performance merges multiple files into a single file
Next:.NET/C# collection List, HashSet to determine whether an element has a benchmark
 Landlord| Posted on 3/10/2024 10:58:59 AM |
.NET/C# Roslyn compiler platform
https://www.itsvse.com/thread-10740-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com