I often get asked how to speed up the .NET applications startup times and my answer is often to try NGEN which pre-compiles assemblies at install time instead of when application is run. Here is a nice guidelines from CLR team at Microsoft that outlines when to actually do that. In short NGEN can help you if:
- You have a large application that has lots of managed code that gets fetched and/or ran at startup. When such application is run the Just-in-time compiler goes and compiles all Intermediate Language code first which of course takes certain amount of time. More code equals longer JIT times resulting in startup delays. Eliminating this steps by using NGEN will help with both cold and warm application startup times.
- You have framework, library or other reusable components. Code that is produced by JIT cannot be shared across multiple processes, but the code produced by NGEN can. When multiple applications are using the same library and component this results in smaller memory footprint and faster loading times since component once loaded is shared between the applications.
- Your application is expected to be running under Terminal Services. This is closely related to previous point since code will be reused in multiple processes.
You should not use NGEN for smaller applications, generally there is no benefit in doing so.
You can read full post here.
Here is also good information on how to integrate NGEN into the setup.
MSDN Magazine also has good article on how to squeeze maximum out of NGEN.
[…] your assemblies using NGEN when appropriate to increase start-up time. Click here to read my short post with guidelines on when to consider doing […]