是否.NET程序集的大小会影响性能?大小、性能、程序、NET

2023-09-02 21:10:24 作者:记忆线上的盛世繁华

做了.NET程序集的大小会影响性能呢?如何组件的Windows窗体/ Web表单的项目有多少?

Does the size of a .net assembly affect performance at all? How about the number of assemblies in your windows forms/web forms project?

推荐答案

从微软的模式与放大器;实践提高.NET应用程序性能和可伸缩性第5章:

From Microsoft's Patterns & Practices Improving .NET Application Performance and Scalability Chapter 5:

preFER单大型装配体而不是多个 较小的组件

Prefer Single Large Assemblies Rather Than Multiple Smaller Assemblies

要帮助减少应用程序的工作集,你应该preFER单个较大 组件而不是多个较小的组件。如果你有多个组件 这总是装在一起,就应该将它们结合起来,创造一个单一的 部件。

To help reduce your application’s working set, you should prefer single larger assemblies rather than multiple smaller assemblies. If you have several assemblies that are always loaded together, you should combine them and create a single assembly.

与具有多个较小的组件相关联的开销可以归因 以下内容:

The overhead associated with having multiple smaller assemblies can be attributed to the following:

加载元数据较小的组件的成本。 在谈到在pre-编译图像的各种内存页的CLR为了 加载组件(如果它是pcompiled与Ngen.exe $ P $)。 在JIT编译时间。 安全检查。 The cost of loading metadata for smaller assemblies. Touching various memory pages in pre-compiled images in the CLR in order to load the assembly (if it is precompiled with Ngen.exe). JIT compile time. Security checks.

由于你付出的只是你的程序访问内存页面,更大 组件提供本机图像生成实用器(Ngen.exe)具有较大 机会来优化它产生的本机映像。图像手段更好的布局 必要的数据,可以更密集地布置,而这又意味着更少的整体 需要的页面做的工作相比,同样code多布局 组件。

Because you pay for only the memory pages your program accesses, larger assemblies provide the Native Image Generator utility (Ngen.exe) with a greater chance to optimize the native image it produces. Better layout of the image means that necessary data can be laid out more densely, which in turn means fewer overall pages are needed to do the job compared to the same code laid out in multiple assemblies.

有时候你无法避免分裂组件;例如,对于版本和 部署的原因。如果你需要单独船型,您可能需要单独 组件。

Sometimes you cannot avoid splitting assemblies; for example, for versioning and deployment reasons. If you need to ship types separately, you may need separate assemblies.