Winforms 如何提高被引用dll的加载性能';什么是启动?

Winforms 如何提高被引用dll的加载性能';什么是启动?,winforms,performance,c#-4.0,dll,devexpress,Winforms,Performance,C# 4.0,Dll,Devexpress,我在.NET 4 framework上有一个windows窗体应用程序,使用的是Devexpress组件。在我的应用程序的第一次运行中,它会等待20或30秒来加载程序集。在那之后它像火箭一样运行:)我怎样才能解决这个问题?我在谷歌上搜索了一些,找到了NGEN.exe。我不知道NGEN是否可用。有没有其他简单的方法来提高负载装配速度?你喜欢什么 安装后是否可以自动运行程序的存根?也就是说,自动加载带有开关的程序,该开关作为安装的最后一步悄悄退出。大多数人预计安装需要几秒钟/分钟,所以大多数人甚至不

我在.NET 4 framework上有一个windows窗体应用程序,使用的是Devexpress组件。在我的应用程序的第一次运行中,它会等待20或30秒来加载程序集。在那之后它像火箭一样运行:)我怎样才能解决这个问题?我在谷歌上搜索了一些,找到了NGEN.exe。我不知道NGEN是否可用。有没有其他简单的方法来提高负载装配速度?你喜欢什么

安装后是否可以自动运行程序的存根?也就是说,自动加载带有开关的程序,该开关作为安装的最后一步悄悄退出。大多数人预计安装需要几秒钟/分钟,所以大多数人甚至不会注意到

更新: 我检查了,它说程序集是按需加载的(根据需要),但您可以使用该方法强制显式加载程序集。如果在用户输入登录信息时预加载程序集(以及可选的依赖项),则会有效隐藏加载延迟。

您有冷启动问题。冷启动时间主要由磁盘驱动器决定,它将程序集定位在磁盘上。热启动很快,程序集存在于文件系统缓存中,因此不必位于慢速磁盘上

使用ngen.exe会使冷启动更糟糕,它需要找到另一个文件。Microsoft建议您仅在大型程序集上使用ngen.exe的原因。Jitting实际上比查找ngen映像文件更快

对于缓慢的冷启动,您无能为力,这纯粹是一个硬件问题,您需要一个更快的磁盘才能真正取得成功。确保对其进行良好的碎片整理肯定会有所帮助。SSD非常好。您可以使用ILMerge.exe减少需要查找的DLL数量。如果用户在机器启动后足够频繁地启动程序,这个问题往往会随着时间的推移自行解决。Windows了解使用模式并预取可执行文件,以便在需要时将其放入文件系统缓存中。一个叫做


Fwiw,慢速冷启动并非.NET程序独有,使用大量DLL的非托管程序也存在此问题。Office和Adobe Reader是常见的例子。他们作弊,他们安装一个在登录时运行的“优化器”。它所做的只是将这些DLL放入文件系统缓存。很烦人。您也可以这样做,当然我不推荐这样做。

如果您正在运行设置为“任意CPU”的WinForms项目,请尝试将其构建为x86(或更喜欢32位),然后看看这是否会有所不同

我特别对.NET 4.5.1 JIT编译器有一个问题,它花费了太长的时间来将两个DevExpress WinForms DLL编译为64位。切换到32位允许我们最重的表单在3秒内冷启动负载,而之前需要35秒

有趣的是,关闭JIT优化也有帮助,因为显然64位优化非常慢。我注意到,我们的发布模式版本的运行速度远远慢于调试版本。作为一个简单的测试,您可以在应用程序文件夹中放置一个简单的
.ini
,以关闭JIT优化,并查看是否有影响:

[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0

如果有任何DevExpress支持人员正在阅读此文章,并且为了子孙后代,这是我在使用某些DevExpress 14.1.3.0 DLL作为64位进行预编译时的NGen输出。我最终没有使用NGen,但它抛出了一些奇怪的错误,您可能会发现这些错误很有用

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

是的,你是对的。我想在登录后我可以这样做。我该怎么做?加载一个不可见的表单并最终处理该表单?我假设组装过程发生在启动时,但这是一个按需操作的过程,我已经更新了我的答案。谢谢你的回答。我发现这与您所说的SuperFetch类似,但并没有看到太多区别:var loadedAssemblies=AppDomain.CurrentDomain.GetAssemblies().ToList();var loadedPaths=loadedsassemblies.Select(a=>a.Location.ToArray();var referencedPaths=Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory,“*.dll”);var-toLoad=referencedPaths.Where(r=>!loadedPaths.Contains(r,StringComparer.InvariantCultureIgnoreCase)).ToList();toLoad.ForEach(路径=>loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(路径)));顺便问一下,我想问一下,使引用“Copy Local”属性为true或false,对冷启动问题有影响吗?如果将其设置为false,则程序将无法运行。冷启动:)