Is there any way to change the .NET JIT compiler to favor performance over compile time?

两盒软妹~` 提交于 2019-12-03 05:32:48

This is set when you compile your assembly. There are two types of optimizations:

  • IL optimization
  • JIT Native Code quality.

The default setting is this

 /optimize- /debug-

This means unoptimized IL, and optimized native code.

 /optimize /debug(+/full/pdbonly) 

This means unoptimized IL, and unoptimized native code (best debug settings).

Finally, to get the fastest performance:

/optimize+ /debug(-/+/full/pdbonly)

This produces optimized IL and optimized native code.

When producing unoptimized IL, the compiler will insert NOP instructions all over the code. This makes code easier to debug by allowing breakpoints to be set on control flow instructions such as for, while,if,else, try, catch etc.

The CLR does a remarkably good job of optimizing code regardless. Once a method is JIT'ed, the pointer on a call or a callvirt instruction is pointed directly to the native code.

Additionally, the CLR will take advantage of any architecture tricks available when JIT'ing your code. This means that an assembly ran through the JIT will run faster than an assembly pre-compiled by using Ngen (albeit with a slightly slower start up time), as NGen will compile for all platforms, and not take advantage of any tricks.

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