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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…