Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does .NET assembly size affect performance?

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

like image 241
Blankman Avatar asked Dec 03 '08 13:12

Blankman


People also ask

What are the benefits of using .NET assembly?

Solution 1. They allow you to break your code into smaller, independent sections that can be worked on individually without changing other code. As an example, take the . NET framework: it is a set of assemblies which you do not need to change, or see the source code for in order to write your application.

What does a .NET assembly contain?

NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest. The designers of . NET have worked a lot on the component (assembly) resolution. An assembly can be a single file or it may consist of the multiple files.

What is the scope of an assembly in C#?

Assemblies are for physical scope and namespaces are for logical scope, so namespaces can be expanded over assemblies but the converse is not possible. The namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally unique types.


1 Answers

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

Prefer Single Large Assemblies Rather Than Multiple Smaller Assemblies

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:

  • 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.

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.

like image 129
Dan Blanchard Avatar answered Sep 27 '22 20:09

Dan Blanchard