Game Development Reference
Also, there are many shared libraries in the .NET class framework that incur sig-
nificant overhead on top of your own code. There is a tool provided with the .NET
framework ( ngen.exe ) that can generate native images of assemblies and store
them in the Global Assembly Cache, essentially precompiling your code for faster
startup times and overall runtime execution in certain situations.
While NGen sounds like the silver bullet for increasing runtime performance,
there are only certain situations when performance can be improved through its
use. Native images cannot be used when crossing application domains, so there is
no real benefit from using NGen for ASP.NET applications. However, generating
native images for Windows Forms can result in a performance increase.
NGen must be run on the assemblies after they have been deployed to the target machine. Doing
so allows the application to be optimized for the machine it is installed on.
There are some situations where your application may perform better with JIT
compilation instead of native images. Some optimizations cannot be done with
native images, so make sure that you profile the startup and operating times of
your application while using native images and JIT compilation. You should also
profile combinations of native images and regular assemblies.
This chapter examined performance considerations when developing applications
for the .NET platform. First, two approaches for investigating performance were
discussed: white box and black box. The rest of the chapter focused on perfor-
mance considerations for commonly used and abused areas of everyday .NET
development. A misconception regarding performance optimization is that a consid-
erable amount of time should be spent on optimizing code down to the compiler
level. In reality, especially with .NET, the majority of performance loss results from
application architecture and design. These problems occur at a high level, and can
be identified using black box performance testing.