Home > OS >  Can the .NET JIT compiler inline methods that are decorated with attributes?
Can the .NET JIT compiler inline methods that are decorated with attributes?

Time:11-08

If there is an attribute (any attribute),there is probably a reason, so in theory, it shouldn't be inlined but it's just a guess.
Do I have to use [MethodImpl(MethodImplOptions.NoInlining)] if I want to suggest I don't want Inlining?

CodePudding user response:

Attributes in general? sure; however, both the compiler and JIT are free to pay special attention to anything in System.Runtime.CompilerServices, and apply special rules (well, technically they can pay special attention to anything at all, but the relevant types tend to be there; counter-examples would be [Obsolete] and [Serializable], which are not in that namespace but which have special rules). [MethodImpl(...)] is one of those attributes with special rules for the JIT.

Attributes in the general sense, however; make no real difference.

Yes, [MethodImpl(MethodImplOptions.NoInlining)] requests that the JIT should not inline this.

  • Related