Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How and when does ngen.exe work?

Tags:

I want to know the benefit of pre-JIT compilation (ngen.exe). What is the role of the Native Image Generator (NGen) process and why is it required?

Please provide an example.

like image 646
Dhiren Avatar asked Dec 16 '13 20:12

Dhiren


People also ask

Where is NGEN exe?

The ngen.exe file is located in a subfolder of C:\Windows (for example C:\Windows\Microsoft.NET\Framework\v4. 0.30319\). Known file sizes on Windows 10/8/7/XP are 141,976 bytes (20% of all occurrences), 171,072 bytes and 6 more variants. The program has no visible window.

How do I get rid of NGEN exe?

Open the Start menu, then click Settings. Click System on the Settings menu, then select Apps & features on the left pane. Select an app you wish to uninstall, then click Uninstall.

How do I delete a net native image?

NET Framework. A native image can be removed by a call to ngen.exe with the approriate switches (call ngen.exe /? to get help): ngen uninstall <assembly name> [scenarios] [config] Delete the native images of an assembly and its dependencies from the Native Images Cache.

What is CSI native image generation?

CSI provides a tool, CSiNativeImageGen.exe, which can be used to generate a native image. This makes use of the Windows Ngen.exe command for . NET framework 4 to pre-compile the software and cache it on the system.


1 Answers

For code execution on the .NET platform, the Common Intermediate Language (CIL) representation needs to be translated into machine code. If this happens immediately before execution this is referred to as JIT (Just In Time) compilation. Output of JIT is not persisted so your managed application has to go through JIT for every launch.

Alternatively, you can use pre-compilation to reduce startup overheads related with JIT compilation. NGen performs pre-compilation and keeps the native images in a native image cache. Then applications can run with the native images and may experience faster startup time due to reduced JIT compilation overhead. Initially, NGen was an install-time technology, developers made application installers issue NGen commands to trigger pre-compilation during install time. For more details, check out NGen Revs Up Your Performance with Powerful New Features. This article provides an example application that leverages NGen.

With Windows 8 (.NET 4.5), a new NGen mode: "Auto NGen" has been introduced. Basically, the .NET runtime generates usage logs for managed applications. When the system is idle, an automatic maintenance task runs in the background and generates native images. This way developers no longer have to deal with NGen explicitly. Note that this feature is only enabled for .NET 4.5+ applications that target Window Store or use the GAC. Here's an MSDN page that may be helpful: Creating Native Images

And this is high-level overview of NGen and related technologies: Got a need for speed? .NET applications start faster

Lastly, .NET framework libraries themselves use NGen for better performance. When .NET framework is serviced, some of the native images get invalidated. Then NGen needs to run to re-generate the invalid native images. This is done automatically via the .NET Runtime Optimization service which runs during idle time.

like image 158
m_eric Avatar answered Sep 20 '22 14:09

m_eric