Why would the .NET JIT compiler decide to not inline or optimize away calls to empty static methods that have no side effects?

前端 未结 1 1896
南笙
南笙 2021-02-05 03:51

I think I\'m observing the .NET JIT compiler not inlining or optimizing away calls to empty static methods that have no side effects, which is a bit surprising given some bespok

相关标签:
1条回答
  • 2021-02-05 04:19

    After digging a bit further, it turns out I can answer this question myself. As explained at http://blogs.msdn.com/b/vancem/archive/2006/02/20/535807.aspx , observing the disassembly of an optimized release build under the debugger will by default affect the JIT compiler.

    Unchecking these

    • ‘Suppress JIT optimization on module load’
    • ‘Enable Just My Code’

    under VS > Tools > Debugging > General, will show the "real" JIT compilation result, which for the call to EmptyBody in my Main above is this:

    004C2620  ret
    

    Meaning that the call to EmptyBody is completely removed, which is what was expected and the world is still a happy and somewhat predictable place to live in :)

    0 讨论(0)
提交回复
热议问题