views:

48

answers:

2

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?

A: 

NGEN allows you to specify a base address (also exposed in VS settings). If you're going to NGEN, you basically want to ensure you don't have any overlap between DLLs. If you have overlap, then the CLR will be forced to rebase them when they're loaded.

HTH,
Kent

Kent Boogaart
@Kent How much of a gap do I need between base addresses?
MakerOfThings7
@Kent Also does ngen override the VS settings?
MakerOfThings7
The gap that's needed depends on the size of the image when loaded, which is quite hard to predict. If you put a few megabytes between them you'll probably be safe.
bdonlan
A: 

The relocating of your DLLs only occurs at load time, once loaded there are no further performance hits due to the relocation process. Of course depending on the number and size of the DLLs (the number of relocations) the load time can be significantly impacted, which is a problem is your application is frequently started and stopped.

Rebasing DLLs to improve load times requires continous monitoring and tuning, if you have not left enough head room between DLL load locations you end up with collisions as the DLLs grow or new DLLs get added to the project.

Here is an MSDN article discussion ways to improve application startup time. http://msdn.microsoft.com/en-us/magazine/cc163655.aspx

Chris Taylor