I was wondering if there's any way to change the behavior of the .NET JIT compiler, by specifying a preference for more in-depth optimizations. Failing that, it would be nice if it could do some kind of profile-guided optimization, if it doesn't already.
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Faster loop: foreach vs some (performance of jsper
- Bulk update SQL Server C#
This is set when you compile your assembly. There are two types of optimizations:
The default setting is this
This means unoptimized IL, and optimized native code.
This means unoptimized IL, and unoptimized native code (best debug settings).
Finally, to get the fastest performance:
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.