tags:

views:

1019

answers:

5

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 ?

Thanks, Chak.

+6  A: 

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.)

Jon Skeet
Before you go down the NGEN route, it's best to first see if you can trim the number of assembly references you are loading - then go down the NGEN route.
Paul Betts
Does ASP.NET really use an NGen'ed assembly?
foson
A: 

Ok thanks. 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. "

http://www.codeguru.com/columns/experts/article.php/c4651

It's worth looking at P19-22 of his book "CLR via C#" for a newer version of that article. Not a lot of changes, but a few. Even within that article though, look near the bottom: (quote in next comment)
Jon Skeet
"Certainly, for server-side applications, NGen.exe makes no sense since only the first client request experiences a performance hit; future client requests run at excellent speed."
Jon Skeet
A: 

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?

alexmac
This was only the case for .NET framework 1.0/1.1In 2.0 and on, native images can be shared across the app domains. See the different versions of http://msdn.microsoft.com/en-us/library/6t9t5wcf.aspx
foson
Cool I didnt realise that thanks!
alexmac
A: 

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

foson
A: 

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?

Nariman