-
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
Unwanted GC root in unused struct on stack #37064
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @Maoni0 |
Does the loop compile in Tier0 i.e. if you add [MethodImpl(MethodImplOptions.AggressiveOptimization)]
private void EventLoop() |
This behavior is by design. The codegen is free to arbitrarily extend the lifetime of locals. Check these discussions for details: |
Tagging subscribers to this area: @dotnet/ncl |
The part I found odd in that function is that in optimized code |
For longer term it may be feasible to separate the handling of events into a |
Ah I just saw on the other issue that you already tried that and saw a regression. It seems a bit surprising that one call per loop iteration would cause a perf regression, how bad is it and are you sure it's outside noise range? |
The JIT is free to create temporary copies of values that are outside your control. I suspect that it is likely happening in this case.
Note that Mono has conservative GC. The Is the extension of the lifetime causing performance issues or functionality issues? If it is causing functionality issues, it would be a good idea to rethink the design to be robust against arbitrary lifetime extensions. |
Oh I see. The issue is that the |
Seems like this is the root cause for #35846. Considering an infinite event loop like the following:
When a local
struct
holds a reference to a heap object, it remains a GC Root, even if it goes out the scope. (IP is waiting infinitely atWaitForSocketEvents()
.)Self-contained repro here:
https://github.com/antonfirsov/SocketEngineCodegenRepro
I was able to reproduce this in both Debug and Release, and observe the GC root with SOS, just like @kouvel did in the original issue: #35846 (comment)
The text was updated successfully, but these errors were encountered: