Welcome to MSDN Blogs Sign in | Join | Help

Performance: One big assembly vs several small assemblies.

I frequently see people ask the same question in microsoft.public.dotnet.framework.clr and microsoft.public.dotnet.framework.performance. Which one has better performance, one big assembly or several small assemblies?

Strictly from a performance point of view, one assembly is always better than several assemblies. Each assembly loading has a fixed overhead. For multiple assemblies, you pay the overhead several times.

The overhead of assembly loading at minimum includes the following:
1. Finding the assembly.
2. Loader in memory data structure tracking this assembly.
3. Assembly initialization.

1. Overhead of finding the assembly.
For .Net assembly, the probing rule is documented here. For strongly named assembly, we will apply policy, then probe in GAC, then in app directory. Applying policy means finding config files and parse them (This is once per AppDomain so the overhead is not always as big as that. Nonetheless we will always look for publisher policy. This cost is always there. ). If your assembly is not in GAC, probing in GAC is a waste for you. All of these means a lot disk access. For simply named assembly, we don't apply policy, and we don't probe GAC so the overhead is smaller. But the overhead is still there.

2. Loader overhead.
Loader always has some overhead for each assembly. Like looking up the appdomain to see if the assembly is loaded or not, registering the assembly in the appdomain. All these has time and memory overhead. For .Net assembly, you pay the overhead three times for each assembly, one in fusion, one in CLR loader, one in OS loader.

3. Assembly initialization.
Every assembly has some initialization cost. If you look at .Net assembly's import table, it has an entry pointing to mscoree!_CorDllMain. This method is executed every time an assembly is loaded. If your assembly is a Manager C++ assembly, it has its own DllMain to execute. It may also need runtime fixup. Also if you use C/C++ runtime library, it has its own initialization.

The cost of above add up when you have multiple assemblies.

There are other cost associated with multiple assemblies. Each assembly has its own metadata. This is extra disk size cost. And one assembly is likely to have better disk sequential distribution than several assemblies. This means the disk access time for several assemblies is going to be longer.

Of course there are many many good reasons why you want multiple assemblies. But from a strict performance point of view, one assembly wins, always.

Published Monday, February 23, 2004 1:32 PM by junfeng
Filed under:

Comments

# re: Performance: One big assembly vs several small assemblies.

Monday, February 23, 2004 5:29 PM by Anonymous Coward
These all seem like one time costs. Are there any runtime costs associated with multiple assemblies?

# re: Performance: One big assembly vs several small assemblies.

Monday, February 23, 2004 7:37 PM by Hans Jergen Ohff
Give us back the linker so we can have assemblies build as .lib modules and we can static link.

# re: Performance: One big assembly vs several small assemblies.

Tuesday, February 24, 2004 12:05 AM by Ferris Beuller
Some way t' static link .net modules would be real damn supa' fine. 'S all
good.

# re: Performance: One big assembly vs several small assemblies.

Tuesday, February 24, 2004 5:09 AM by Panos Theofanopoulos
Does the AppDomain has a limit to the loaded assemblies it can handle (IIRC at BETA times was 99)?

# re: Performance: One big assembly vs several small assemblies.

Tuesday, February 24, 2004 5:38 AM by Junfeng Zhang
I am a loader person, so this one time startup cost means the whole world to me;)

Joel Spolsky complained about the linker in http://www.joelonsoftware.com/articles/PleaseLinker.html. And Jason Zander rebuted here http://weblogs.asp.net/jasonz/archive/2004/01/31/65653.aspx.

Panos, I am not aware of any limit to the loaded assemblies in each appdomain. At least in fusion we do not post any limit.

# re: Perf trade off: lots of small assemblies or fewer bigger assemblies??

Thursday, May 06, 2004 12:59 PM by Brad Abrams

# What is new in Fusion in .Net framework 2.0 (1) ---- Fusion.dll is....gone?

Wednesday, June 30, 2004 3:14 AM by Junfeng Zhang

# re: Performance: One big assembly vs several small assemblies.

Monday, August 02, 2004 3:10 AM by dianying xia zai
http://www.dmoz.net.cn/ wangzhidaquang
http://www.86dmoz.com/ jingpingwangzhi
http://www.kamun.com/ mianfeidianying
http://movie.kamun.com/ dianyingxiazai
http://music.kamun.com/ MP3 free download
http://www.pc530.net/ diannaoaihaozhe
http://www.5icc.com/ duangxingcaixingxiazha
http://www.dianyingxiazai.com/ dianyingxiazai
http://www.yinyuexiazai.com/ yinyuexiazai

# Re: Object Orientated Design Question

Monday, June 02, 2008 12:07 PM by Channel 9

While this posting doesn't specifically discuss solution design, it does discuss the performance implications of single assembly vs. multiple assemblies.

New Comments to this post are disabled
 
Page view tracker