-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InlineArray in generic class #106129
Comments
Moving to runtime as this is a question about the ASM code generation. |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
The generic type is used for |
For current 9.0 milestone I'd ask to add a warning in docs "Don't use InlineArray with reference types for performance reason". This will save someone a lot of time searching for the reasons why their code is slow. |
Can you share a benchmark that shows a perf problem warranting such a statement? Your code here always throws |
Yes, sharplab example is minimal asm demo. I attached working benchmark project for you. |
I get the following results:
In general we expect shared generic code to be slightly slower than unshared code. For example, you will also see a slowdown for Thoughts @dotnet/jit-contrib @jkotas? |
Currently only the backend liveness pass will DCE calls without side effects when their result is unused. However, unused runtime lookups can end up expanded to control flow that we will be unable to DCE. This teaches the middle-end liveness pass to DCE dead calls as well. Fix dotnet#106129
While I was researching this problem, I measured this example too and the differences there are scanty, there is an understanding of this and it is acceptable. If we compare 1 and 3 lines (InlineArray code - value vs referense) - diff is 2.47!
I don't insist on documenting. But the problem is that there are intuitive expectations that the new InlineArray is designed for high-performance code, although it works worse than the usual language constructs. |
`gtNodeHasSideEffects` is meant to check if a node has side effects when you exclude its children. However, it was checking arguments of calls which is more conservative than expected. The actual reason we were doing that seems to be `gtTreeHasSideEffects` that sometimes wants to ignore `GTF_CALL` on pure helper calls. It was relying on this check in `gtNodeHasSideEffect`; instead move it to `gtTreeHasSideEffects` where it belongs. This is an alternative fix for dotnet#106129; there we leave a `COMMA(CORINFO_HELP_RUNTIMELOOKUP_METHOD, ...)` around because extracting side effects from op1 does not end up getting rid of the call. Fix dotnet#106129
Steps to Reproduce:
This example code does nothing with the parametric type value except to read and return as a result.
Therefore, it was surprising to find a strong difference in the code size and performance for value and reference types.
Is this expected?
See sharplab
Expected Behavior:
Code for value types and reference types is almost the same, performance is almost the same.
Actual Behavior:
Code for reference types is much larger and works 2-3 times slower.
The text was updated successfully, but these errors were encountered: