Does it help to use NGEN?
Asked Answered
T

5

18

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.

Twink answered 22/12, 2008 at 9:19 Comment(0)
B
23

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

Bray answered 22/12, 2008 at 9:24 Comment(6)
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.Disaccustom
Does ASP.NET really use an NGen'ed assembly?Pd
Could you elaborate a bit more about the Performance Manager graphs? If I google it, I am in a recursion to this post :(Damali
@ChristianGollhardt: I'm far from an expert, but if you open Performance Manager you can add graphs for all kinds of things.Bray
@JonSkeet - according to Jeff Richter, NGen on ASP.NET or Service libraries should not get any performance gain since they are always loaded as domain-neutral - see here under "Ignored NGen'd File in Some Domain Load Scenarios" codeguru.com/csharp/.net/net_general/toolsand3rdparty/… Am I missing something?Tripartite
@DaveBlack: Well, aside from anything else, that article was written in 2002. That was in the C# 1.0 days. An awful lot has changed since then. (An awful lot has changed since I wrote this answer, too. It's nearly 10 years old.) It's still entirely possible that NGen won't help regular ASP.NET - but my caveat around "You should check whether the JIT time is even significant" is still relevant.Bray
P
10

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

Pd answered 2/6, 2009 at 5:6 Comment(0)
E
1

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?

Expenditure answered 21/10, 2009 at 20:13 Comment(0)
E
0

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?

Elsewhere answered 28/5, 2009 at 21:59 Comment(1)
This was only the case for .NET framework 1.0/1.1 In 2.0 and on, native images can be shared across the app domains. See the different versions of msdn.microsoft.com/en-us/library/6t9t5wcf.aspxPd
K
0

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.

Kattegat answered 2/8, 2014 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.