*****.NET程序首次加載慢問題

Why does my code take longer to execute the first time it's run?

Article Details

from:

http://www.devexpress.com/Support/Center/p/A2670.aspx
A2670

2011/6/3
.NET (WinForms)
n/a

The first time I run my application which contains the XtraGrid, it takes one to two seconds on my machine to finish loading data. Subsequently it loads much faster 100-200ms. What is causing this performance variation?

Solution

This is a specific of .NET that any code takes longer to execute the first time it's run. When you build your application, it is compiled into the Microsoft Intermediate Language (MSIL). When the application is launched, the code is compiled into machine code just at runtime. This process may be slow. Additionally, the first execution may require additional DLLs to be loaded, such as the XtraGrid assemblies in your example. Subsequent calls to the same code are performed much faster, because the required libraries are already loaded and the code is already compiled.

Generally, to estimate performance, build a Release version of your application and launch it from Windows Explorer rather than from Visual Studio. If the initial loading is still slow, thorough profiling is recommended. If JIT is proven to be the cause of the problem, use the Native Image Generator (Ngen.exe) tool.

See Also:
Boosting the Performance of the Microsoft .NET Framework
Performance Considerations for Run-Time Technologies in the .NET Framework
Improving Application Startup Time

原文地址:https://www.cnblogs.com/luoyaoquan/p/2114260.html