当前位置:网站首页>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
边栏推荐
- node 的运行命令
- 【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
- Unreal 本地化 国家化 多语言
- QT(41)-多线程-QTThread-同步QSemaphore-互斥QMutex
- 【TypeScript】深入学习TypeScript枚举
- MySQL stored procedure introduction, creation, case, delete, view "recommended collection"
- xss课堂内容复现
- 如何用好建造者模式
- After the tester with 10 years of service "naked resignation" from the big factory...
- 链栈的应用
猜你喜欢
随机推荐
基于单向链表结构的软件虚拟定时器的设计与构建
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
composition-api
三种方式设置特定设备UWP XAML view
Common methods of js's new Function()
3. Byte stream and character stream of IO stream
腾讯云胡启明:Kubernetes云上资源的分析与优化
【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库
web漏洞扫描器-awvs
Web3安全风险令人生畏,应该如何应对?
两种白名单限流方案(redis lua限流,guava方案)
嵌入式分享合集28
[21天学习挑战赛——内核笔记](二)——设备树基础
无代码平台字段设置:基础设置入门教程
visual studio 2015 warning MSB3246
【2022杭电多校5 1003 Slipper】多个超级源点+最短路
如何用好建造者模式
伺服电机矢量控制原理与仿真(1)控制系统的建立
STP基本配置及802.1D生成树协议的改进
格密码入门









