In .NET, will empty method calls be optimized out?

前端 未结 4 1247
时光说笑
时光说笑 2021-01-07 17:41

Given an empty method body, will the JIT optimize out the call (I know the C# compiler won\'t). How would I go about finding out? What tools should I be using and where shou

4条回答
  •  温柔的废话
    2021-01-07 18:36

    This chap has quite a good treatment of JIT optimisations, do a search on the page for 'method is empty', it's about half way down the article -

    http://www.codeproject.com/KB/dotnet/JITOptimizations.aspx

    Apparently empty methods do get optimised out through inlining what is effectively no code.

    @Chris: I do realise the that the methods will still be part of the binary and that these are JIT optimisations :-). On a semi-related note, Scott Hanselman had quite an interesting article on inlining in Release build call stacks:

    http://www.hanselman.com/blog/ReleaseISNOTDebug64bitOptimizationsAndCMethodInliningInReleaseBuildCallStacks.aspx

提交回复
热议问题