当前位置:网站首页>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
边栏推荐
猜你喜欢

After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten

无代码平台字段设置:基础设置入门教程

面试官:Redis中过期的key是怎么被删除的?

伺服电机矢量控制原理与仿真(1)控制系统的建立

【2022杭电多校5 1003 Slipper】多个超级源点+最短路

1、File对象学习

拒绝服务攻击DDoS介绍与防范

IPV6地址
![[TypeScript] In-depth study of TypeScript enumeration](/img/27/4836e59528bb5a51ffc1cf9961c6b6.png)
[TypeScript] In-depth study of TypeScript enumeration

如何最简单、通俗地理解爬虫的Scrapy框架?
随机推荐
如何用好建造者模式
[TypeScript] In-depth study of TypeScript enumeration
如何最简单、通俗地理解爬虫的Scrapy框架?
机器学习_02
链队
visual studio 2015 warning MSB3246
Zero-knowledge proof - zkSNARK proof system
基于单向链表结构的软件虚拟定时器的设计与构建
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
无代码平台字段设置:基础设置入门教程
Apache服务器的配置[通俗易懂]
格密码入门
KubeSphere简介,功能介绍,优势,架构说明及应用场景
ts集成和使用
推荐系统_刘老师
【随记】新一天搬砖 --20220727
Nuxt.js的优缺点和注意事项
MATLAB中readtimetable函数用法
【AGC】构建服务1-云函数示例