-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Enable escape analysis and use in vn #103148
Enable escape analysis and use in vn #103148
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
… stack allocation
FYI @EgorBo @jakobbotsch @SingleAccretion This allows a limited amount of propagation for fields of non-escaping heap objects. I would like VN to know that the backing storage for non-escaping heap object fields is all zero -- any suggestions on the best way to implement that? Also I am tempted to say that non-escaping news have no effect on the global heap state... still thinking about that one. Finally I'd like to enable dead store for fields of nonescaping heap objects (with the hope that perhaps we eventually can remove all reads and writes, and then somehow realize the allocation itself is dead, and remove that too). VN based dead store only considers local defs, and it's not structured in a way that generalizes to field defs. I was going to tack the heap based version on here anyways, and only run it if (a) we have nonescaping news; (b) something (perhaps VN) detects that there are heap stores that are not needed. In a related set of changes, I have support for adding field seqs to boxes, which would light up all of the above for boxes too... I haven't tried running the two together yet. |
Is the main benefit here expected to come from boxes? How much work do you think it would be to enable the more general object stack allocation for boxes and have this fall out from physical promotion instead?
This sounds similar to #96942. When I looked at it I didn't immediately see how to represent this in VN, since memory is handled on a field-by-field basis. |
Test failure is the object allocation test, we now stack allocate in one more case (because of non-escaping helper info).
We know the class, so we could enumerate the fields and add zero stores to each field, but that seems a bit clunky. |
Stats on asp.net are pretty dire -- for optimized methods
And just one method with a diff. |
The current analysis is pretty limited, it even won't account for cases like: var b = new B(42);
var a = new A(b); // the current analysis considers b being escaped
Console.WriteLine(a.Inner.V);
record A(B Inner);
record B(int V); |
It is, but there is also some healthy skepticism that it's fundamentally never going to be very good. However, I am surprised there are so few non-escaping allocations. I would at least expect to see a more sizeable number of non-escaping boxes in generic code. So we'll need to dig in somehow and see what's up. |
Escape analysis has indeed gotten a bit stale, with some small fixes the number of non-escaping news increased from 87 to 153. If I break it down by ref class / value class, I lose a lot of SPMI contexts (since we seemingly don't ask for the class attribs all that often), but of the contexts that survive, I see
So perhaps a bit more encouraging: if we can show 1% of boxes don't escape... including the one from #9118, perhaps it is worth pushing further. |
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
Note this does not enable stack allocation of ref classes—the aim is to let downstream phases treat the memory from non-escaping objects more aggressively, since it's not exposed cross-thread.