-
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
JIT fails to escape simple usage of List<>
and []
#111838
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
It's not de-abstract, which is applied to virtual calls. Instead, it's about escape analysis to cancel object allocation. De-allocation of struct was just merged recently (#104906). De-allocation of objects is much more complex and hasn't been done yet. |
Right, I was thinking of that exact word. I will update the issue.
Is there any existing issue which refers to it for tracking? |
List<>
and []
List<>
and []
I don't know any actual work has started now. The topic of broader escape analysis is covered by #108931 . /cc @AndyAyersMS |
While they may seem similar, a list is quite a bit more complicated than an array and requires new capabilities to optimize. Some of the work in .NET 10 may chip away at this, but I would not expect the whole thing to be optimized. |
Out of curiosity: why would one do an optimization as in the OPs example in the JIT, and not already as a lowering pass when generating MSIL? |
The component that generates the msil does not have the information necessary to do these optimizations. |
C# compiler can't see the implementation of In more common cases, the operations can spread in multiple methods that can be inlined together. |
Thanks for explaining |
Was tinkering around JIT generated code for
List<>
and raw arrays for very simple below code.The code is very self explanatory, nothing magical or complex as such. I was comparing the machine code generated by each method. I was expecting JIT to see the code flow and optimize the code gen generated for
ListUsage
andArrayUsage
to be similar asExpected
method, but it does not.Below are things JIT can see and I would expect it to optimize it further.
List<int> numbers
(in methodListUsage
) andint[] numbers
(in methodArrayUsage
) are declared inside the method and get destroyed in method itself at the end (does not get pass to any other method). It even sees the maximum size of those data structure which is1
so ideally it should stack allocate those instead of doing heap allocation.Expected
method in above code.Tested against main branch on CC => https://godbolt.org/z/eWv6Yaoaj
The text was updated successfully, but these errors were encountered: