IT Community - Software Programming, Web Development and Technical Support

What is Native Image Generator (Ngen.exe) in asp.net?

This is a discussion on What is Native Image Generator (Ngen.exe) in asp.net? within the ASP and ASP.NET Programming forums, part of the Web Development category; What is Native Image Generator (Ngen.exe) in asp.net?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 07-26-2007, 03:01 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 631
oxygen is on a distinguished road
Question What is Native Image Generator (Ngen.exe) in asp.net?

What is Native Image Generator (Ngen.exe) in asp.net?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 07-26-2007, 03:06 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 880
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Default Re: What is Native Image Generator (Ngen.exe) in asp.net?

The Native Image Generator utility (Ngen.exe) allows you to run the JIT compiler on your assembly'sMSIL and generate native machine code which is cached to disk. After the image is created .NETruntime will use the image to run the code rather than from the hard disk. Running Ngen.exe onan assembly potentially allows the assembly to load and execute faster, because it restores code and data structures from the native image cache rather than generating them dynamically.

Below are some points to be remembered for Native Image Generator:-

Native images load faster than MSIL because JIT compilation and type-safety verifications eliminated.
If you are sharing code between process Ngen.exe improves the performance significantly. As Native image generated Windows PE file so a single DLL file can beshared across applications. By contrast JIT produced code are private to an assembly and can not be shared.
Native images enable code sharing between processes.
Native images require more storage space and more time to generate.
Startup time performance improves lot. We can 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 an application must be loaded from the hard disk, does not benefit as much from native images because the hard disk access time shadows everything.
Assemblies in GAC do not benefit from Native image generator as the loader performs extra validation on the strong named assemblies thus shadowing the benefits of NativeImage Generator.

If any of the assemblies change then Native image should also be updated.
You should have administrative privilege for running Ngen.exe.
While this can fasten your application startup times as the code is statically compiled but it can be somewhat slower than the code generated dynamically by the JIT compiler. So you need to compare how the whole application performance with Ngen.exe and with out it.
To run Ngen.exe, use the following command line

.ngen.exe install <assemblyname>

This will synchronously precompile the specified assembly and all of its dependencies. The generatednative images are stored in the native image cache.
In .NET Framework 2.0 there is a service (.NET Runtime Optimization Service) which can recompile managed assemblies in the background. You can schedule your assemblies to be precompiled asynchronously by queuing them up with the NGEN Service. Use the following command line.

ngen.exe install <assemblyname> /queue:<priority>

Assemblies which are critical to your application's start up time should either be precompiled synchronously or asynchronously with priority 1. Priority 1 and 2 assemblies are precompiled aggressively while Priority 3 assemblies are only precompiled during machine idle-time.Synchronously precompiling your critical assemblies guarantees that the native images will beavailable 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 dependencies (if no other assemblies are dependent on them) from the native image cache by running the following command.

ngen.exe uninstall <assemblyname>

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 part of the application's setup program. Visual Studio .NET can be used to implement this behavior by defining custom actions in a Microsoft Installer (MSI) package
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Password generator using C# .net oxygen C# Programming 4 06-25-2009 07:04 PM
What is Ngen.exe in DotNet? leoraja8 VB.NET Programming 11 10-31-2007 01:17 AM
SQL Server Native Client Sathish Kumar Database Support 1 08-22-2007 12:43 AM
How do I call the native API from Java? oxygen Java Programming 2 08-06-2007 07:43 AM
What are native methods? How do you use them? vadivelanvaidyanathan Java Programming 1 07-17-2007 05:10 AM


All times are GMT -7. The time now is 12:27 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
Stamford Dentist | Euro Millions Lottery | Tech Support Services

SEO by vBSEO 3.0.0