Search code examples
.netasp.netoptimizationrebasengen

How do I prevent NGEN from rebasing my code (negatively affecting performance)?


I simply want to speed up my .NET-base client side app and am considering NGEN-ing the code.

Jeffery Richter wrote this warning about ngening code:

•Inferior Load-Time Performance (Rebasing). When Windows loads an NGend file, it checks to see if the file loads at its preferred base address. If the file cant load at its preferred base address, then Windows relocates the file, fixing-up all of the memory address references. This is extremely time consuming because Windows must load the entire file into memory and modify various bytes within the file. For more information about rebasing please see my book: Programming Applications for Microsoft Windows, 4th Edition (Microsoft Press).

Since I don't know much about this topic, what should I know before I start changing settings within my project, and what settings should I change?


Solution

  • According to this Microsoft blog, "There may be some marginal cases where setting base addresses in Vista+ OSes has a benefit, but these can be largely ignored." So, while using ngen does improve startup times, it is no longer necessary to set the base addresses unless you support pre-Vista OSes. This is a side-effect of the new Address Space Layout Randomization security feature.