Does it help to use NGEN?

℡╲_俬逩灬. 提交于 2019-11-27 04:31:18

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

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

Nariman

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!