Explain image generator (ngen.exe), DOT NET Programming

Image Generator (Ngen.exe)

The Ngen.exe (Native Image Generator) allows you to run the JIT compiler on your assembly's MSIL and generate native machine code which is cached to disk. When the image is created, .NET runtime will use the image to run the code rather than from the hard disk. The Running of Ngen.exe on an assembly potentially allows the assembly to load & execute faster, since it restores the code and data structures from the native image cache rather than generating them dynamically.

Following are some points to keep on mind for Native Image Generator:-

1) The Native images load faster as compared to MSIL as  JIT compilation and type-safety verification is eliminated.

2) If you are sharing code between process the Ngen.exe increase the performance significantly. As the Native image generated Windows PE file so a single DLL file is shared across applications. On contrast JIT produced code are private to an assembly and can not be shared.

3) Start up time performance improves a lot. We  get considerable gains when applications share component assemblies because after the first application has been started the shared components are already loaded for subsequent applications. If assemblies in the  application must be loaded from hard disk, it does not benefit as much from native images as the hard disk access time shadows everything.

4)The Assemblies in the GAC do not benefit from Native image generator as the loader performs extra validation on the strong named assemblies thus shadowing the benefits of Native Image Generator.

5) If any one of the assemblies changes then Native image should also be updated.

6)You should have the administrative privilege for running the  Ngen.exe.

7)While this may fasten your application start up time as the code is statically compiled but it can be somewhat slower than the code generated dynamically through  the JIT compiler.Thus you need to compare how the whole application performance with Ngen.exe and how iot goes without it.

To run the Ngen.exe, we can use the following command line.

ngen.exe install

This will synchronously precompile the specified assembly and all of its dependencies. And the generated native images are stored in the native image cache.

In the .NET Framework 2.0 there is a service (.NET Runtime Optimization Service) which can precompile managed assemblies at  the background. Assemblies can be schedule  to be precompiled asynchronously by queueing them up with the NGEN Service. We use the following command line.

ngen.exe install /queue:

Assemblies that are critical to your application's start up time should either be precompiled synchronously or by asynchronously with  1. Priority 1 &  2 assemblies are precompiled aggressively while the Priority 3 assemblies are only precompiled during the machine idle-time. Synchronously precompiling your critical assemblies assure you that the native images will be available on prior to the first time your end user launches the application but increases the time taken to run your application's set up program.

You can uninstall an assembly and its all dependencies (if no other assemblies are dependent on them) from the native image cache by running the following command.

ngen.exe uninstall

Native images created using Ngen.exe cannot be deployed; instead they need to be created on the end user's machine. These commands therefore need to be issued as the part of the application's setup program. The .NET Visual Studio can be used to implement this behavior by defining custom actions in a Microsoft Installer (MSI) package.

Posted Date: 9/21/2012 7:05:47 AM | Location : United States

Related Discussions:- Explain image generator (ngen.exe), Assignment Help, Ask Question on Explain image generator (ngen.exe), Get Answer, Expert's Help, Explain image generator (ngen.exe) Discussions

Write discussion on Explain image generator (ngen.exe)
Your posts are moderated
Related Questions
I want a Panel for youtube views and facbook likes. I need a panel made that can increase facebook fanpage likes, and that will increase youtube video views. Youtube views an

Question: (a) How can you simple-bind controls at design mode? (b) How can a blank record be created in a dataset bound to the controls in a Windows form? (c) Datagrid

Nutritional properties of Processing food Processing food, you may have realized that many desirable changes occur, which include development of pleasing colours and flavors, i

I have a code in C# which uses Microsoft Solver Foundation to solve linear programming model. But the problem is the code is too long, there are too many variables and constraints,

Social Media project Project Description: It's a Windows Phone application which requires the subsequent capabilities: -Live Video Streaming -Social Networking capabili

What is serialization, how it works in .NET? Serialization is when you persist the state of an object to a storage medium so an exact copy can be re-created at a later stage. S

The Cache object is always defined in the System.Web.Caching namespace. You can get the reference to the Cache object by either using the Cache property of the HttpContext class in

What is Dispose method in .NET? The .NET provides "Finalize" method in which we can clean up our resources. But relying on this is not always better so the best is to implement

VB.net Rewrite and Redirect Rules using CodeBehind Project Description: Need VB.net programmer to make some (hopefully) minor code edits to resolve some site issues. I will p

What is marshalling and types of marshalling? The Marshaling is used when an object is converted so that it can be sent across the network or across the application domains. Th