I've dug through the .NET 5 JIT in an attempt to understand how it determines whether a method should be inlined or not (so I know whether to spam method inlining attributes)
There's a lot of info. I'll strip out most of it so I can leave in the important parts (keep in mind this is my own understanding so some parts may be incorrect. If you have a correction, let me know)
The JIT has different "policies" for inlining that decide in different ways whether or not a method should be inlined. This gist attempts to break down the default policy, which is the one you should be concerned with most of the time
(Keep in mind that at this stage, all methods are still in IL form)
The JIT takes the following precautions before it even thinks about inlining a call to a method regardless of any attributes it has:
- If the method is virtual, do not inline