4

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?

7wp
  • 12,505
  • 20
  • 77
  • 103
  • Did you precompile your web application before deployment? See the link http://msdn.microsoft.com/en-us/library/bb398860.aspx – Yuriy Rozhovetskiy Jun 03 '11 at 15:03
  • @1stein I am using the `web application` project, not `web site` project, so it should already be compiling everything into the BIN subdirectory. – 7wp Jun 03 '11 at 15:20

3 Answers3

5

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 /OffRoot folder 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 AppDomain where 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).

Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129
  • Thanks I am going to use the Web Deployment Project to compile everything including .aspx files into one assembly (http://weblogs.asp.net/scottgu/archive/2008/01/28/vs-2008-web-deployment-project-support-released.aspx) – 7wp Jun 03 '11 at 16:28
1

AFAIK, ASP.NET is based in the .NET world of doing things. Which, of course, means that there's actually two parts to compilation. One is that you compile the source into the .NET bytecode format. Second is the actual conversion into a format suitible to actually run on your system, usually in a Just-In-Time fashion. This is similar to Java, though there's a lot of lower-level differences.

The issue is that it's currently doing this JITting up-front, which is by design. It can take a while to get the ASP.NET app up and working, which is the minute you're seeing. I do believe there is a way to enable pre-JITting prior to having someone actually visit the site, but I'm not sure of the exact manner. Hopefully someone will post/link to the actual method for doing it.

Gary McConnell
  • 125
  • 1
  • 4
0

Check index.aspx or default.aspx to see if there are any web applications. Sometimes it takes time to find the files, and compilation takes a while only first time.

Servy
  • 202,030
  • 26
  • 332
  • 449
Bhargav Mistri
  • 944
  • 8
  • 20
  • that doesen't make any sense. Then why would the framework spend 57 seconds in the function `CompileNonDependentBuildProviders`? also please note that there is a difference between a `web site` project and `web app` project. I think Matthew Abbott covered why this is happening. Even though the code behind for the web app is compiled, the .aspx parts are not, and that is what takes the hit the first time the server starts. – 7wp Jun 03 '11 at 18:50