25

What is the difference between the MethodImplAttribute with the option MethodImplOptions.AggressiveInlining and the TargetedPatchingOptOut?

When I searched on Google everybody seems to says that both (might) inline the method but without giving the difference.

abatishchev
  • 92,232
  • 78
  • 284
  • 421
Yann Lebel
  • 625
  • 1
  • 7
  • 16
  • 5
    TargetedPatchingOptOut is quite well explained here: http://stackoverflow.com/questions/6109745 The crucial part seems to be that the inlining is performed across assembly boundaries, which is not done by default. I would expect that AggressiveInlining is a hint to inline the method, but unlike TargetedPatchingOptOut does not allow inlining across assembly boundaries. – dtb Mar 10 '13 at 04:56
  • After I read your comment I did a little bit more research and found this [link](http://blogs.microsoft.co.il/blogs/sasha/archive/2012/01/20/aggressive-inlining-in-the-clr-4-5-jit.aspx). My understanding of this post is that you can apply both attribute AggressiveInlining will remove the size limit of the method while like you said the TargetedPatchingOptOut will allow inlining accross assembly boundaries. Is that correct? – Yann Lebel Mar 10 '13 at 06:18
  • That's how I'd interpret it as well. – dtb Mar 10 '13 at 06:32
  • How to i mark your comment as answer? – Yann Lebel Mar 10 '13 at 08:13
  • You can't -- it's a comment :-) You seem to have spent more effort on this than me, so feel free to post an answer to your question yourself and accept it. – dtb Mar 10 '13 at 08:19
  • 6
    @dtb and Yann: See [here](http://stackoverflow.com/questions/14937647/14982340#14982340). tl;dr: inlining across assembly bounds is already done by the JIT for everything but the .Net core library, where `TargetedPatchingOptOut` is useful. For everyone else (all of us), `TargetedPatchingOptOut` is completely useless. – BlueRaja - Danny Pflughoeft Jun 13 '13 at 20:50
  • Thats good to know, thank you. – Yann Lebel Jun 14 '13 at 01:21

1 Answers1

13

I was waiting to see if someone else could have a better answer but it seems no.

After I read dtb comment I did a little bit more research and found this http://blogs.microsoft.co.il/blogs/sasha/archive/2012/01/20/aggressive-inlining-in-the-clr-4-5-jit.aspx.

My understanding of this post is that you can apply both attribute AggressiveInlining will remove the in-lining size limit of the method while like dtb said the TargetedPatchingOptOut will allow inlining accross assembly boundaries.

Yann Lebel
  • 625
  • 1
  • 7
  • 16
  • 7
    As mentioned above, don't apply TargetedPatchingOptOut in your own code - see http://stackoverflow.com/a/14982340/94078 – eug Jan 06 '14 at 10:59