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

こ雲淡風輕ζ 提交于 2019-11-30 11:41:14

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

If you believe you are being impacted by JIT, then precompile your app with NGEN and run the tests again. There is no JIT overhead in code that has been compiled by NGEN. If you still see spikes in the NGEN'd app, then you know they are not caused by JIT.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!