-
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
Remove another reference field from async state machines #83737
Conversation
Tagging subscribers to this area: @dotnet/area-system-threading-tasks Issue DetailsThe async state machine Task-derived type currently adds three fields:
The other pending PR gets rid of the Action field by using the unused Action field from the base Task for that purpose. This PR gets rid of the ExecutionContext field by using the unused state object field from the base Task for that purpose. The field is exposed via the public AsyncState property, so this also uses a bit from the state flags field to prevent this state object from being returned from that property. The combination of removing those two fields shaves 16 bytes off of every
|
The async state machine Task-derived type currently adds three fields: - The StateMachine - An Action field for caching any delegate created to MoveNext - The ExecutionContext to flow to the next MoveNext invocation The other pending PR gets rid of the Action field by using the unused Action field from the base Task for that purpose. This PR gets rid of the ExecutionContext field by using the unused state object field from the base Task for that purpose. The field is exposed via the public AsyncState property, so this also uses a bit from the state flags field to prevent this state object from being returned from that property. The combination of removing those two fields shaves 16 bytes off of every `async Task` state machine box on 64-bit. The only remaining field added by the state machine type is for the state machine itself, which is required.
Looking forward to your next PR removing that field too |
I spent a little bit of time trying to understand if it made sense to hoist the |
Right. Moving it back from contingent properties would end up penalizing TCS tasks (and others like them, e.g. Task.Delay, Task.WhenAll, etc.), as well as delegate-backed ones (e.g. Task.Run, Task.ContinueWith, etc.) when in the default ExecutionContext. I decided that all around this was the better tradeoff, since it doesn't make anything measurably more expensive and it makes |
The async state machine Task-derived type currently adds three fields:
The other pending PR gets rid of the Action field by using the unused Action field from the base Task for that purpose.
This PR gets rid of the ExecutionContext field by using the unused state object field from the base Task for that purpose. The field is exposed via the public AsyncState property, so this also uses a bit from the state flags field to prevent this state object from being returned from that property.
The combination of removing those two fields shaves 16 bytes off of every
async Task
state machine box on 64-bit. The only remaining field added by the state machine type is for the state machine itself, which is required.