Forcing the .NET JIT compiler to generate the most optimized code during application start-up

You can trigger the JIT compiler to compile your entire set of assemblies during your application's initialization routine using the PrepareMethod ... method (without having to use NGen).

This solution is described in more detail here: Forcing JIT Compilation During Runtime.


The initial speed indeed sounds like Fusion+JIT, which would be helped by ILMerge (for Fusion) and NGEN (for JIT); you could always play a silent track through the system at startup so that this does all the hard work without the user noticing any distortion?

NGEN is a good option; is there a reason you can't use it?

The issues you mention after the initial load do not sound like they are related to JIT. Perhaps garbage collection.

Have you tried profiling? Both CPU and memory (collections)?


As Marc mentioned, the ongoing spikes do not sound like JIT issues. Other things to look for:

  • Garbage collection - are you allocating memory during your audio processing? If you're creating a lot of garbage, or even objects which survive a Gen 0 collection, this might cause noticible spikes. It sounds like you are doing some kind of pre-allocation, but watch out for hidden allocations in library code (even a foreach loop can allocate!)

  • Denormals. There is an issue with certain types of processors when dealing with very small floating point numbers which can cause CPU spikes. See http://www.musicdsp.org/files/denormal.pdf for details.

Edit:

Even if you don't want to use NGen, at least compare an NGen'd version so you can see what difference JITing makes