runtime: RyuJIT should not inline throw only methods

The ThrowArgsNull method in the following example gets inlined even though there’s no reason to do so, throwing exceptions isn’t fast to begin with and such codepaths aren’t supposed to be common anyway. The inlined code size is significantly larger than the call site (in this example 57 bytes vs 5 bytes).

using System;
class Program {
    static void Main(string[] args) {
        if (args == null)
            ThrowArgsNull();
    }
    static void ThrowArgsNull() {
        throw new ArgumentNullException("args");
    }
}

More generally, there’s probably no reason to inline any method that doesn’t contain at least one BBJ_RETURN block.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 25 (23 by maintainers)

Most upvoted comments

@briansull I experimented with this when reporting the issue and rejecting inlining seemed easy enough. I suppose marking the block as RarelyRun should be trivial but that’s not enough to get best CQ. The BB kind should also be changed to something that works like BBJ_THROW, otherwise you end up with unnecessary registers spills/moves.