One of the first things that people might notice when they're running managed applications is that the startup time is slower than it is for a "native" application. The major cause of this slowdown is the actual compilation that needs to happen (just in time [JIT] compiling). Because the managed code must be compiled into native code before it's executed, this compilation provides an expected delay when starting the application. Because Managed DirectX is built on top of this system, code you write using the Managed DirectX runtime has this behavior as well. Because the JIT compilation can do a lot of optimizations that just can't happen during compile time (taking advantage of the actual machine the code is running on rather than the machine it was compiled on, and so on) the behavior here is desired. The side effect (the slowdown) is not. It would be great to find a way to remove this cost. Luckily for us, the .NET Framework includes a utility called Native Image Generator (NGen), which does exactly that. This utility natively compiles an assembly and puts the output into what is called the native assembly cache, which resides within the global assembly cache. When the .NET Framework attempts to load an assembly, it checks whether the native version of the assembly exists, and if it does, it loads that instead of doing the JIT compilation at startup time, potentially dramatically decreasing the startup time of the application using these assemblies. The downsides of using this utility are twofold. First, there's no guarantee that the startup or execution time will be faster (although in most cases it is so you should test to find out), and second, the native image is "fragile." A number of factors cause the native image to become invalid (such as a new runtime installation or security settings changes). After the native image is invalid, it still exists in the native assembly cache and is never used. Plus, if you want to regain the benefits, you need to NGen the assemblies once more, and unless you're watching closely, you might not even notice that the original native assemblies are now invalid. If you've decided you would still like to NGen your Managed DirectX assemblies, here are the steps you would take:
If you later decide you do not want the assemblies compiled natively, you can use the ngen /delete command to remove these now compiled assemblies. Construction Cue
|