I have an windows forms application on .NET 4 framework and using Devexpress components. In first run of my application it wait 20 or 30 seconds for loading assemblies. After that it runs like a rocket :) How can I solve this? I googled some and found NGEN.exe. I don't have any idea NGEN is usable or not. Is there any another simple way for increase load assembly speed? What do you prefer?
You have a cold start problem. Cold start times are dominated by the disk drive, locating the assemblies on disk. A warm start is fast, the assemblies are present in the file system cache so don't have to be located on the slow disk.
Using ngen.exe makes cold starts worse, it requires another file to be found. The reason that Microsoft recommends that you only ever use ngen.exe on large assemblies. Jitting can actually be faster than finding the ngen image file.
There's not that much you can do about slow cold starts, it is a pure hardware problem and you need a faster disk to truly get ahead. Making sure it is defragged well certainly helps. An SSD is very nice. You could use ILMerge.exe to reduce the number of DLLs that need to be found. It is a problem that tends to solve itself over time if the user starts the program often enough after machine startup. Windows learns the usage pattern and prefetches executables so they'll be in the file system cache when needed. A feature called SuperFetch.
Fwiw, slow cold starts are not exclusive to .NET programs, unmanaged programs that use lots of DLLs have this problem too. Office and Adobe Reader are common examples. They cheat, they install an "optimizer" that runs at login. All it does is get those DLLs into the file system cache. Very annoying. You could do this too, of course I can't recommend that.
If you are running your WinForms project set to "Any CPU", try building it as x86 (or prefer 32-bit) instead and see if that makes a difference.
I specifically had an issue with the .NET 4.5.1 JIT compiler taking way too long to compile a couple of DevExpress WinForms dlls as 64-bit. Switching to 32-bit allowed our heaviest form to cold-start load in 3 seconds, whereas before it was taking 35 seconds.
Interestingly enough turning off the JIT optimization also helped, as apparently the 64-bit optimization was very slow. I noticed that our Release mode builds were running far slower than our Debug builds. As an easy test you can put a simple <App Executable Name>.ini
in your application folder to turn off JIT optimization and see if makes a difference:
[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0
If any DevExpress support staff are reading this post and for posterity sake, here was my NGen output when pre-compiling with some DevExpress 14.1.3.0 dlls as 64-bit. I ended up not using NGen, but it threw some strange errors which you may find useful.
E:\Applications\Pryme>C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install Pryme.exe
Microsoft (R) CLR Native Image Generator - Version 4.0.30319.18408
Copyright (c) Microsoft Corporation. All rights reserved.
Failed to load dependency DevExpress.XtraMap.v14.1 of assembly DevExpress.Dashboard.v14.1.Win, Version=14.1.3.0, Culture
=neutral, PublicKeyToken=b88d1754d700e49a because of the following error : The system cannot find the file specified. (E
xception from HRESULT: 0x80070002)
Failed to load dependency DevExpress.Map.v14.1.Core of assembly DevExpress.Dashboard.v14.1.Core, Version=14.1.3.0, Cultu
re=neutral, PublicKeyToken=b88d1754d700e49a because of the following error : The system cannot find the file specified.
(Exception from HRESULT: 0x80070002)
Failed to load dependency DevExpress.XtraMap.v14.1 of assembly DevExpress.Dashboard.v14.1.Core, Version=14.1.3.0, Cultur
e=neutral, PublicKeyToken=b88d1754d700e49a because of the following error : The system cannot find the file specified. (
Exception from HRESULT: 0x80070002)
Failed to load dependency DevExpress.XtraCharts.v14.1.Extensions of assembly DevExpress.XtraReports.v14.1.Extensions, Ve
rsion=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a because of the following error : The system cannot find
the file specified. (Exception from HRESULT: 0x80070002)
3> Compiling assembly DevExpress.SpellChecker.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d
700e49a (CLR v4.0.30319) ...
2> Compiling assembly DevExpress.XtraSpellChecker.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d7
00e49a (CLR v4.0.30319) ...
4> Compiling assembly DevExpress.Data.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (CLR
v4.0.30319) ...
1> Compiling assembly E:\Applications\Pryme\Pryme.exe (CLR v4.0.30319) ...
2> Compiling assembly DevExpress.Utils.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (CLR
v4.0.30319) ...
3> Compiling assembly DevExpress.Printing.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e
49a (CLR v4.0.30319) ...
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
2> Compiling assembly DevExpress.XtraEditors.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49
a (CLR v4.0.30319) ...
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
4>Cannot embed generic MethodDesc while compiling method PropVariant.GetVector
3> Compiling assembly DevExpress.Sparkline.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700
e49a (CLR v4.0.30319) ...
3> Compiling assembly Merydyan.Pryme.SI, Version=3.0.18.34925, Culture=neutral, PublicKeyToken=null (CLR v4.0.30319)
...
4> Compiling assembly Merydyan.Pryme.Core, Version=3.0.18.34915, Culture=neutral, PublicKeyToken=null (CLR v4.0.30319
) ...
3> Compiling assembly NodaTime, Version=1.2.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1 (CLR v4.0.30319) ..
.
4> Compiling assembly AutoMapper, Version=3.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005 (CLR v4.0.30319)
...
3> Compiling assembly Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da (CLR v4.0.30319) ...
4> Compiling assembly EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (CLR v4.0.30
319) ...
3> Compiling assembly Merydyan.Pryme.Data, Version=3.0.18.34919, Culture=neutral, PublicKeyToken=null (CLR v4.0.30319
) ...
2> Compiling assembly EntityFramework.Extended, Version=6.0.0.0, Culture=neutral, PublicKeyToken=05b7e29bdd433584 (CL
R v4.0.30319) ...
1> Compiling assembly Merydyan.Pryme.Services, Version=3.0.18.34923, Culture=neutral, PublicKeyToken=null (CLR v4.0.3
0319) ...
2> Compiling assembly Humanizer, Version=1.28.0.0, Culture=neutral, PublicKeyToken=979442b78dfc278e (CLR v4.0.30319)
...
3> Compiling assembly DevExpress.XtraReports.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49
a (CLR v4.0.30319) ...
2> Compiling assembly DevExpress.Office.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49
a (CLR v4.0.30319) ...
1> Compiling assembly DevExpress.XtraCharts.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
(CLR v4.0.30319) ...
2> Compiling assembly DevExpress.Charts.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49
a (CLR v4.0.30319) ...
3> Compiling assembly DevExpress.PivotGrid.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700
e49a (CLR v4.0.30319) ...
2> Compiling assembly DevExpress.RichEdit.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e
49a (CLR v4.0.30319) ...
1> Compiling assembly DevExpress.XtraGauges.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d70
0e49a (CLR v4.0.30319) ...
3> Compiling assembly DevExpress.XtraGrid.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (
CLR v4.0.30319) ...
1> Compiling assembly DevExpress.XtraLayout.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
(CLR v4.0.30319) ...
1> Compiling assembly DevExpress.XtraPrinting.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e4
9a (CLR v4.0.30319) ...
4> Compiling assembly DevExpress.XtraBars.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (
CLR v4.0.30319) ...
1> Compiling assembly DevExpress.XtraTreeList.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e4
9a (CLR v4.0.30319) ...
3> Compiling assembly DevExpress.XtraScheduler.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e
49a (CLR v4.0.30319) ...
4>Cannot embed generic MethodDesc while compiling method MouseEventSubscriber`1.PreFilterMessage
1> Compiling assembly DevExpress.XtraScheduler.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754
d700e49a (CLR v4.0.30319) ...
3> Compiling assembly DevExpress.XtraScheduler.v14.1.Extensions, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b8
8d1754d700e49a (CLR v4.0.30319) ...
3> Compiling assembly DevExpress.XtraWizard.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
(CLR v4.0.30319) ...
1> Compiling assembly DevExpress.Dashboard.v14.1.Win, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e
49a (CLR v4.0.30319) ...
3> Compiling assembly DevExpress.Dashboard.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700
e49a (CLR v4.0.30319) ...
3>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.XtraMap.v14.1, Version=14.1.3.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the file specified
.. If this assembly is found during runtime of an application, then the native image currently being generated will not
be used.
3>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.Map.v14.1.Core, Version=14.1.3.0
, Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the file specifie
d.. If this assembly is found during runtime of an application, then the native image currently being generated will not
be used.
1>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.XtraMap.v14.1, Version=14.1.3.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the file specified
.. If this assembly is found during runtime of an application, then the native image currently being generated will not
be used.
1>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.Map.v14.1.Core, Version=14.1.3.0
, Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the file specifie
d.. If this assembly is found during runtime of an application, then the native image currently being generated will not
be used.
3>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.XtraMap.v14.1, Version=14.1.3.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the file specified
. (Exception from HRESULT: 0x80070002). If this assembly is found during runtime of an application, then the native imag
e currently being generated will not be used.
3>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.Map.v14.1.Core, Version=14.1.3.0
, Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the file specifie
d. (Exception from HRESULT: 0x80070002). If this assembly is found during runtime of an application, then the native ima
ge currently being generated will not be used.
1>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.XtraMap.v14.1, Version=14.1.3.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the file specified
. (Exception from HRESULT: 0x80070002). If this assembly is found during runtime of an application, then the native imag
e currently being generated will not be used.
4>Cannot embed generic MethodDesc while compiling method MouseEventSubscriber`1.PreFilterMessage
4> Compiling assembly DevExpress.DataAccess.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
(CLR v4.0.30319) ...
1> Compiling assembly DevExpress.Xpo.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (CLR v
4.0.30319) ...
3> Compiling assembly DevExpress.XtraGauges.v14.1.Win, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700
e49a (CLR v4.0.30319) ...
4> Compiling assembly DevExpress.XtraGauges.v14.1.Presets, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754
d700e49a (CLR v4.0.30319) ...
2> Compiling assembly DevExpress.XtraCharts.v14.1.Wizard, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d
700e49a (CLR v4.0.30319) ...
3>Cannot embed generic MethodDesc while compiling method GaugeDataBindingPage`1.OnSelectedItemChanged
3>Cannot embed generic MethodDesc while compiling method GaugeDataBindingPage`1.OnSelectedItemChanged
3> Compiling assembly DevExpress.Utils.v14.1.UI, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (
CLR v4.0.30319) ...
4> Compiling assembly DevExpress.XtraRichEdit.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e4
9a (CLR v4.0.30319) ...
3> Compiling assembly DevExpress.XtraVerticalGrid.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d7
00e49a (CLR v4.0.30319) ...
2> Compiling assembly DevExpress.XtraNavBar.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
(CLR v4.0.30319) ...
3> Compiling assembly DevExpress.XtraCharts.v14.1.UI, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e
49a (CLR v4.0.30319) ...
1> Compiling assembly DevExpress.DataAccess.v14.1.UI, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e
49a (CLR v4.0.30319) ...
3> Compiling assembly DevExpress.CodeParser.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
(CLR v4.0.30319) ...
2> Compiling assembly DevExpress.XtraPivotGrid.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e
49a (CLR v4.0.30319) ...
4> Compiling assembly DevExpress.XtraRichEdit.v14.1.Extensions, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88
d1754d700e49a (CLR v4.0.30319) ...
1> Compiling assembly DevExpress.XtraPdfViewer.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e
49a (CLR v4.0.30319) ...
1> Compiling assembly DevExpress.Pdf.v14.1.Core, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (
CLR v4.0.30319) ...
4> Compiling assembly DevExpress.Pdf.v14.1.Drawing, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49
a (CLR v4.0.30319) ...
2> Compiling assembly DevExpress.XtraReports.v14.1.Extensions, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d
1754d700e49a (CLR v4.0.30319) ...
4> Compiling assembly WebCam_Capture, Version=1.0.2395.24959, Culture=neutral, PublicKeyToken=null (CLR v4.0.30319) .
..
2>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.XtraCharts.v14.1.Extensions, Ver
sion=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the
file specified.. If this assembly is found during runtime of an application, then the native image currently being gener
ated will not be used.
4> Compiling assembly DevExpress.XtraScheduler.v14.1.Reporting, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88
d1754d700e49a (CLR v4.0.30319) ...
4> Compiling assembly DevExpress.Xpf.Core.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (
CLR v4.0.30319) ...
2>Warning: System.IO.FileNotFoundException: Could not load file or assembly 'DevExpress.XtraCharts.v14.1.Extensions, Ver
sion=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the
file specified. (Exception from HRESULT: 0x80070002). If this assembly is found during runtime of an application, then t
he native image currently being generated will not be used.
3> Compiling assembly DevExpress.Mvvm.v14.1, Version=14.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a (CLR
v4.0.30319) ...
1> Compiling assembly Merydyan.Pryme.UI.Windows, Version=3.0.18.34928, Culture=neutral, PublicKeyToken=null (CLR v4.0
.30319) ...
E:\Applications\Pryme>C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install Pryme.exe
Maybe automatically run a stub of the program after install? That is, automatically load the program with a switch that exits silently as the last step in your install. Most people expect installs to take a few seconds/minutes so most people wont even notice.
UPDATE: I checked the MSDN C# documentation and it says assemblies are loaded on demand (as needed) but you can force them to load explicitly using the Assembly.ReflectionOnlyLoadFrom method. If you preload your assemblies (and optionally the dependencies) while the user is entering login info then you'll effectively hide the loading delay.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With