Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Too many dynamic assemblies

Tags:

c#

razor

I am attempting to use the Razor view engine as a general templating engine backed by a database.
http://razorengine.codeplex.com/ The problem is that for every template compilation a new dynamic assembly is created and loaded. As there is no way to unload an assembly from the current appdomain and no way to use a separate appdomain for the templating system (use of anonymous types) these assemblies will keep accumulating until the appdomain is destroyed. The templates themselves will change on a regular basis and as such will result in more recompiles.

The question is will these dynamic assemblies (potentially thousands) hurt the appdomain performance? Or alternately is there a better way to do this?

like image 797
Danielg Avatar asked Jun 13 '11 19:06

Danielg


1 Answers

In general having many small assemblies loaded in the AppDomain shouldn't be something to worry about too much. The only general statement anyone could make about this is to measure the actual performance of the app in the relevant scenarios and then see if it matters.

ASP.NET has some automatic app lifecycle management that will recycle the AppDomain after certain events. For example, if there are too many recompilations in the app then ASP.NET will automatically restart the app. This means that all the previously loaded assemblies will be cleared out and you start from scratch.

See MSDN for more info: http://msdn.microsoft.com/en-us/library/s10awwz0.aspx

numRecompilesBeforeAppRestart

Optional Int32 attribute.

Specifies the number of dynamic recompiles of resources that can occur before the application restarts. This attribute is supported at the global and application level but not at the directory level.

Note

ASP.NET increases the NumRecompilesBeforeAppRestart property every time an assembly is invalidated and fails to be deleted.

The default is 15.

like image 167
Eilon Avatar answered Sep 22 '22 04:09

Eilon