1. JITComplier
As you know, the JIT (just-in-time or "instant") compiler is an important component of CLR, and its responsibility is to convert IL into local cpu commands.
<CLR via C #> The following figure shows the first call of a method (WriteLine) in the CLR execution model section:
When the JITComplier function is called, it knows which method to call and what type it defines. Then, JITComplier searches for the IL of the called method in the metadata that defines the type of assembly, then JITComplier verifies the IL code, and finally translates the IL code into local CPU commands. The local CPU command is saved to a dynamically allocated memory block.
Here we will insert the MSIL. We know that. NET hosted Assembly includes both metadata and IL. IL is a machine language unrelated to the CPU. It can be considered as an object-oriented machine instruction, or understood as an advanced assembly language, but it is more advanced than most CPU machine languages. IL can access and manipulate object types, and provides instructions to create and initialize objects, call Virtual Methods on objects, and directly operate on array elements, it even provides instructions for throwing and capturing exceptions to handle errors.
A method that has been verified and compiled by JITComplier. During the second call, the code in the memory block is executed directly, and the JITComplier function is skipped completely, therefore, a method may cause some performance loss only when it is called for the first time.
Main features of JITComplier:
1. Compile at runtime;
2. methods required for each compilation;
3. Memory exists after compilation;
4. The code generated by the compiler is bound to the process that triggers the compilation and cannot be shared among multiple processes.
、Ngen.exe
. NET framework.exe refers to the ngen.exe tool, which is a local code generator or a local image generator. It can compile the IL code at the local cost when an application is installed on a user's computer.
Since the code has been compiled during installation, the CLR JITComplier does not need to compile the IL code at runtime, which seems to help improve the performance of the application.
Why does "looks" help improve application performance? Does NGen.exe improve the performance of. NET applications? In your opinion, ngen.exe can reduce JITComplier's verification and compilation. Isn't this part of overhead saved?
Ngen.exe only accelerates application startup. The execution speed is not faster than the Code Compiled by JITComplier. The main reason is that ngen.exe produces poor code when compiling code, which is beyond the control of the final execution environment. For example, NGen cannot optimize some CPU commands, and access to static fields requires indirect operations rather than direct access, because the actual address of static fields must be known at runtime. NGen inserts code everywhere to call the class constructor because it does not know the code execution sequence or whether the class constructor has been called.
Main features of NGen.exe:
1. Compile before running;
2. Compile the entire assembly at a time;
3. stored permanently on a local disk after compilation;
4. You can share compiled code among multiple processes.
Of course, the files generated by ngen.exe also have some typical problems, such as lack of intellectual property protection, the possibility of file synchronization loss, difficult to manage, and poor execution performance, for details, refer To to To-NGen-or-Not-to-NGen.
You can use the ngen.exe tool under frameworkvia the command line. For specific parameters, refer to MSDN
Iii.. NET Native
These two days have been a hot topic on blogs and Weibo. The reason is that Microsoft announced the. NET Native Developer Preview on the MSDN blog .. NET Native can compile C # code at the cost of local machine code. With it, developers will not only enjoy the high productivity of C #, but also enjoy the performance of C/C ++. With NET Native, we can have both the productivity of C # And the combat capability of C ++.
It seems that MS is the best way to go. functions and performance, efficiency and experience, platforms and open source are indispensable.
Refer:
<CLR via C #>
Http://www.cnblogs.com/flier/archive/2004/07/08/22340.html
Http://www.codeguru.com/csharp/.net/net_general/toolsand3rdparty/article.php/c4651/JIT-Compilation-and-Performance--To-NGen-or-Not-to-NGen.htm
Http://msdn.microsoft.com/en-US/vstudio/dn642499.aspx
Http://blogs.msdn.com/ B /dotnet/archive/2014/04/02/announcing-net-native-preview.aspx