当前位置:网站首页>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
边栏推荐
猜你喜欢
知识分享|如何设计有效的帮助中心,不妨来看看以下几点
[2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL
3、IO流之字节流和字符流
Oreo domain name authorization verification system v1.0.6 public open source version website source code
mdk5.14无法烧录
c语言小项目(三子棋游戏实现)
js数据类型、节流/防抖、点击事件委派优化、过渡动画
C语言——青蛙跳台阶(递归)
Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
【PCBA方案设计】握力计方案
随机推荐
新式茶饮,卷完水果还能卷什么?
香港暂停进口俄罗斯部分地区禽肉及禽类产品
88. (the home of cesium) cesium polymerization figure
机器学习_02
dotnet 删除只读文件
Oreo域名授权验证系统v1.0.6公益开源版本网站源码
Matlab画图2
3. Byte stream and character stream of IO stream
C语言小笔记+题
ts集成和使用
Configure laravel queue method using fort app manager
dotnet 通过 WMI 获取系统安装软件
手撕SparkSQL五大JOIN的底层机制
五分钟入门文本处理三剑客grep awk sed
C语言基础[通俗易懂]
2、字符集-编码-解码
mdk5.14无法烧录
链队
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
三种方式设置特定设备UWP XAML view