当前位置:网站首页>dotnet enables JIT multi-core compilation to improve startup performance
dotnet enables JIT multi-core compilation to improve startup performance
2022-08-04 20:57:00 【Lin Dexi】
It takes 2 minutes to improve the startup performance by one-tenth, and the startup performance can be improved by starting JIT multi-core compilation in the desktop program. In dotnet, the startup performance of the software can be improved by allowing JIT to perform multi-core compilation. In the default managed ASP.NETThe program is enabled, and it needs to be manually opened for desktop programs such as WPF.
Add the following code to the Main function or App's constructor to open
using System.Runtime;ProfileOptimization.SetProfileRoot(@"C:\lindexi\");ProfileOptimization.StartProfile("Startup.Profile");
Set a folder in SetProfileRoot. This folder needs to be an existing folder. If it is set to a folder that does not exist, then this method will not be abnormal, but will not do anything
Set a file name in StartProfile, which will record the function that needs to be called when the file is started
Principle
On devices that can perform multi-threaded computing, one thread can run the code, and multiple threads can perform JIT compilation to improve performance.
Set a folder in SetProfileRoot, which will store files used to improve performance, in StartProfile will create a binary file to record the functions that need to be called at startup
When the program is run for the first time, it will judge whether there are files to improve performance. If not, collect the functions that need to be called in the background at startup, and record these functions in the files to improve performance.
When the program is run for the second time, because there is already a performance-improving file, reading this file can know the functions that need to be called at startup, so the background multi-threaded JIT compilation is performed to these methods that will be called
/p>
Enable this function
By default, this function is enabled in ASP.NET. If you need to disable this function, please add the following code to the web.config file
Desktop programs such as WPF are not enabled by default. You need to call the two functions mentioned at the beginning of this article to enable them. It should be noted that the order of the two methods is fixed. First set the folder and then set the file. Note that the set folder needs to beThe file exists and can be written to at the same time
Please call SetProfileRoot two functions during program execution, such as Main or App constructor
If an application has different running methods according to the incoming command line, such as the software I am working on, there are two different methods: lesson preparation and teaching. These two different methods start the method that needs to be called.If they are not the same, you need to use two different files in StartProfile through the command line, and use different files for different modes
ProfileOptimization.SetProfileRoot(@"C:\lindexi\");if (Editing){// Now enter lesson preparation modeProfileOptimization.StartProfile("Editing.Profile");}else{// now using the teaching methodProfileOptimization.StartProfile("Displaying.Profile");}
Here you can use different files according to different command parameters, so that different commands can do different optimizations for different startup methods used
Environment
Required on a non-single-core device, and on .NET Framework 4.5 and above or dotnet core 3.0 and above
Performance
After many tests, I found that the time required to call the two functions of SetProfileRoot is about 0.2 ms on my device, which is not too short. At the same time, I found that the actual time to the completion of the software startup has hardly improved
Because the startup time of many software is in file reading and writing, not in JIT compilation time
So there is almost no improvement in startup performance without this function and startup
Why isn't this feature turned on in the default desktop program?Because this function needs to read and write files that improve performance, it is difficult to know where the file should be placed by default, and the time to read the file at startup is often longer than JIT compilation.
In ASP.NET, you can automatically read files that improve performance by hosting, so it is used in ASP.NET by default
You can also use ladder compilation at software startupThe methods used in the process use fast compilation methods to reduce the time of JIT execution
边栏推荐
猜你喜欢
Web3时代的战争
Zero-knowledge proof - zkSNARK proof system
文章复现:超分辨率网络-VDSR
xss课堂内容复现
Configure laravel queue method using fort app manager
项目难管理?先学会用好甘特图(内附操作方法及实用模板)
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
[2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL
[TypeScript] In-depth study of TypeScript enumeration
随机推荐
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
【PCBA方案设计】握力计方案
括号匹配
Zero-knowledge proof - zkSNARK proof system
Five Minutes Introductory Text Processing Three Musketeers grep awk sed
二叉搜索树解决硬木问题
构建Buildroot根文件系统(I.MX6ULL)
dotnet 使用 lz4net 压缩 Stream 或文件
拒绝服务攻击DDoS介绍与防范
格密码入门
1、File对象学习
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
腾讯云胡启明:Kubernetes云上资源的分析与优化
STP基本配置及802.1D生成树协议的改进
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
Desthiobiotin-PEG4-Azide_脱硫生物素-叠氮化物 100mg
xss课堂内容复现
Web3时代的战争
Red5搭建直播平台
基于单向链表结构的软件虚拟定时器的设计与构建