*****.NET程序首次加載慢問題
Article Details
from:
|
|
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