NGen 和 Gacutil 最佳实践

发布于 2024-07-25 14:51:08 字数 363 浏览 3 评论 0原文

我一直在开发一个 WinForms 应用程序,它有大约 5 个引用的程序集 - 由我们编写,以及大约 8 个由第三方引用的程序集(我们不希望将来更新它们,除非出现严重错误 - Infragistics/DevExpress 组件! )。

我们的冷启动时间有点太长了,我想知道是否将它们添加到 Gac 中并进行生成是可行的方法。

当我们安装到 NGen 缓存中时,它是否也需要安装到 gac 中? 两者有何联系? 我应该以哪个为目标? 我们有一个 exe,我会做一个 ILMerge,但我不确定这是否适用于我们的场景 - 说来话长。

另外,是否可以获得我的 exe 占用了多少内存 - 就像 Java 应用程序一样(例如 Netbeans!)

I've been working on a WinForms application which has about 5 referenced assemblies - written by us, and about 8 referenced assemblies by third parties (we wont be hoping to update them in the future unless something goes terribly wrong - Infragistics/DevExpress components!).

Our startup times are a little too high on cold boots, what I'm wondering is whether adding them to the Gac and ngen'ing them is the way to go.

When we're installing into the NGen cache, does it need to be in the gac too? Whats the connection between the two? Which should I be aiming for? We have one exe, I'd do an ILMerge but I'm not sure that will work in our scenario - long story.

Also, is it possible to get how much memory my exe is taking - much like the Java applications do (like Netbeans!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以歌曲疗慰 2024-08-01 14:51:08

缩短启动时间的主要思想是尽可能使用延迟初始化。 不要在启动后立即实例化不必要的东西。 使用 延迟初始化 模式。 也可以在显示主窗体后启动后台初始化工作程序来执行非关键初始化。 等等等等。

您还可以查看以下文章(改善应用程序启动时间)

Main idea to improve startup time is to use delayed initialization whenever possible. Do not instantiate things that unnecessary immediately after startup. Use lazy init pattern. It is also possible to start background initialization worker after show main form to do non-critical initialization. Etc, etc, etc.

You can also check the following article (Improving Application Startup Time).

寒江雪… 2024-08-01 14:51:08

在我看来,您的问题定义在某种程度上暗示了您的解决方案☺

换句话说,您如何知道启动时间来自加载程序集?

您应该做的是分析应用程序并确保情况确实如此。 这是可能的,但是如果正在进行一些初始化并且您过于关注优化错误的位置怎么办?

这里有一些可以帮助您分析非托管应用程序的工具。

既然您谈论的是 Winforms 应用程序,我假设您有 Visual Studio。 如果是这样,您可以为托管应用使用其分析器

祝你好运!

Sounds to me that your problem definition is somehow implying your solution ☺

In other words, how do you know that the start up time is coming from loading the assemblies?

What you should do is to profile the app and make sure that's the case. It's possible, but what if some initialization is going on and you are focusing too much optimizing the wrong spot?

Here there are some tools that should help you out on profiling unmanaged apps.

Since you are talking about Winforms apps, I assume you have Visual Studio. If so, you can use its profiler for your managed app.

Good luck!

听风念你 2024-08-01 14:51:08

如果您没有使用 .net 框架 3.5 SP1,您应该考虑在该平台上进行基准测试,看看是否有差异。 已做出一些改进,可能会缩短应用程序的启动时间:.NET Framework 中的 CLR 优化3.5 SP1

本文也有一些很好的一般准则、ngen 最佳实践以及避免程序集变基的技巧(尽管对于您正在使用的 5 个左右引用的程序集,不要指望奇迹)。

然而,通过找出您自己的特定应用程序中的特定瓶颈,而不是在其他地方寻找快速解决方案,您可能会获得最显着的启动时间减少。

If you are not using 3.5 SP1 of the .net framework you should consider benchmarking on that platform to see if you get a difference. There have been improvements made that might improve app startup times : CLR Optimizations In .NET Framework 3.5 SP1

This article also has some good general guidelines, ngen best practices, and tricks with avoiding the rebasing of your assemblies (although for the 5 or so referenced assemblies you are working with, dont expect miracles).

However its likely you'll get the most signficant reduction in startup time by seeking out the specific bottlenecks in your own particular app, as opposed to finding a quick fix elsewhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文