views:

65

answers:

3

If Ngen doesn't protect my application, when would I reasonably expect to use this application in my career?

A: 

Loading speed is all it is really useful for. That said, it can make up to a 2000% (yes that is correct) improvement.

Edit:

Please note that JIT'ed code normally tends to be faster than NGEN'ed code.

leppie
Can I NGEN ASP.NET? When would I need to re-run NGEN?
MakerOfThings7
for ASP.NET you would rather use precompilation.
XIII
You could, if you know you know your application will not change frequently. Also you would have to use the `aspnet_compiler` to make sure all your 'front end' code gets compiled into assemblies as well.
leppie
@Leppie Is this related to the ASP Warmup tool by Microsoft? I haven't gone too deep into it.
MakerOfThings7
+1  A: 

NGen is only for compiling the IL for performance increases. You would want to look into code obfuscation for protecting the app from reverse engineering.

klabranche
+2  A: 

Jeffrey Richter wrote a great piece in his book, I don't know if the third release has it, but here is a great piece he wrote in 2002 about Ngen'ing which is still relevant.

Highlights:

Meanwhile, there are several potential problems with respect to NGen'd files:

  • No Intellectual Property Protection. Many people believe that it might be possible to ship NGend files without shipping the files containing the original IL code thereby keeping their intellectual property a secret. Unfortunately, this is not possible. At runtime, the CLR requires access to the assemblys metadata and the NGend files do not contain the metadata.

  • NGend Files Can Get Out-Of-Sync. When the CLR loads an NGen'd file it compares a number of attributes about the previously-compile code and the current execution environment. If any of the attributes don't match then the NGen'd file cannot be used and the normal JIT compiler process is used instead.

  • Poor Administration. NGen'd file are not automatically deleted when an assembly is uninstalled adversely affecting the .NET Frameworks easy administration and XCOPY deployment story.

  • 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).

Inferior Execution-Time Performance.

When compiling code, NGen cant make as many assumptions about the execution environment as the JIT compiler can. This causes NGen.exe to produce code with a number of memory-reference indirections that aren't necessary for JIT compiled code

RandomNoob
There should be no 'admin' issues. I have have not even had an NGEN'ed assembly with the same version cause ill effects (because it wont load if the hash dont match).
leppie
I just posted a followup question here: http://stackoverflow.com/questions/3591699/how-do-i-prevent-ngen-from-rebasing-my-code-negatively-affecting-performance
MakerOfThings7