Question

Is it better to use NGEN an ASP.NET application when we know it is not going to change much? Or is the JIT good enough?

The only reason I asked was because this article by Jeffrey Richter in 2002 says :

And, of course, Microsoft is working quite hard at improving the CLR and its JIT compiler so that it runs faster, produces more optimized code, and uses memory more efficiently. These improvements will take time. For developers that can't wait, the .NET Framework redistributable includes a utility called NGen.exe.

Was it helpful?

Solution

NGen will only help startup time - it doesn't make the code execute any faster than it would after JITting. Indeed, I believe there are some optimizations which NGen doesn't do but the JIT does.

So, the main question is: do you have an issue with startup time? I don't know how much of an ASP.NET application's start-up time will be JITting vs other costs, btw... you should probably look at the Performance Manager graphs for the JIT to tell you how much time it's really costing you.

(In terms of availability, having multiple servers so you can do rolling restarts is going to give you much more benefit than a single server with an NGENed web app.)

OTHER TIPS

NGen isn't the way to go for ASP.NET -- the creation of the .dlls in the bin folder isn't the final step -- they are compiled again with the web/maching.config settings applied into your C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files folder. Instead of NGen, to decrease initial load-time, use the Publish Website Tool or aspnet_compiler.exe

I'm not sure that NGEN's primary benefit is to start-up time alone - if the application's suffering from a high '% Time in JIT', this is listed as a potential remedy: http://msdn.microsoft.com/en-us/library/dd264972(VS.100).aspx.

The discussion is closely related to a different question on how JIT'd machine code is cached and re-used?

I was looking into this tonight and came across the following:

The common language runtime cannot load images that you create with NGEN into the shared application domain. Because ASP.NET standard assemblies are shared and are then loaded into a shared application domain, you cannot use Ngen.exe to install them into the native image cache on the local computer. http://support.microsoft.com/kb/331979

Not sure if this just refers to assemblies referenced from ASP.net app or the app itself?

Yes it does, this youtube video demonstrates it actually Video of NGEN.exe performance tuning

But word of caution check , check and then implement it.

NGen helps startup time. For example, the Entity Framework documentation says this about the benefit of running NGen:

Empirical observations show that native images of the EF runtime assemblies can cut between 1 and 3 seconds of application startup time.

The context is just the Entity Framework assemblies. NGenning other assemblies would provide additional speedup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top