Open hypeartist opened 5 years ago
@AndyAyersMS @dotnet/jit-contrib
The jit currently won't inline any method that calls a generic virtual method (GVM). I'm not entirely sure why. This restriction may no longer be necessary, or perhaps can be relaxed for some cases.
In code that is performance sensitive, GVMs are usually avoided as calls to GVMs require special runtime support and have high runtime costs. But if everything is instantiated over value types like it is here, I think we can probably do better.
As a workaround, if you can re-express what you're doing without GVMs you should see devirtualization working fairly well for examples like this.
Let me think about this a bit more (it may be a while as I am working through some health issues). In the meantime if you can find more examples of these patterns in your code or elsewhere, please update this issue.
Also if you have a more complete example you can point me at, perhaps we can create a benchmark or something similar.
I can't figure out which devirtualization cases are implemented at the moment of .NET Core 3.0 RC. Here is a quick and dirty example of some common (for me at least) use-cases:
The conclusion is that the only method that get inlined is
DoTestImpl6<T>
The rest five methods are ends up with:Is it expected behavior or I am missing something?
full JitDump output
UPD2: And to make things a little more confused here is another test example (this time completely ready-to-run):
This time we get successfully inlined those two methods:
While the method:
Fails to get inlined with that reason:
Full JitDump output
category:cq theme:devirtualization skill-level:expert cost:medium impact:small