I have an ASP.Net application that takes an unusually long time to start up the first time it is accessed. I did some tracing and I found that 57 seconds are spent in this function:
Boolean System.Web.Compilation.WebDirectoryBatchCompiler.CompileNonDependentBuildProviders(ICollection)
and that function in turn calls the following one 6 times:
Void System.Web.Compilation.WebDirectoryBatchCompiler.CompileAssemblyBuilder(AssemblyBuilder)
My question is what does System.Web.Compilation.WebDirectoryBatchCompiler.CompileAssemblyBuilder do? My web application is already compiled, I don’t know why it is doing any kind of compilation work on start-up. Is this normal? Is there something going on that I don’t know about?
There is quite a bit of bootstrapping that occurs when an ASP.NET application is started. This includes the worker process kicking in, assemblies loaded into the
AppDomain, and also compilation of files in the current directory. This batch compilation process is per folder, which means if I request/for the first time, the batch compiler will scan the folder for supported types, compile them, and cache the result. This is only done within the root/folder. My first request to another/OffRootfolder will result in another batch compile.If you have a precompiled site, the runtime still performs this type of scan but determines that it doesn’t have to compile anything.
There is an important difference between a pre-compiled Website, and a compiled Web Application. A pre-compiled Website will have this first-instance compilation done ahead of time, so it need only load the assemblies into the
AppDomainwhere it needs to. With a compiled Web Application, you have compiled base source code, but the views (.aspx) files are not compiled, so it still does that first-time compilation (dynamic compilation).