-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Share CompletedTask between Task and AsyncTaskMethodBuilder #25423
Share CompletedTask between Task and AsyncTaskMethodBuilder #25423
Conversation
There may be application or framework code that special-cases Since changing the runtime type of |
The benefit of this change is minuscule, like maybe 500 bytes saved total in the best case. Given the breaking potential described by @GrabYourPitchforks, I do not think we should take it - even for next version. |
If it was going to break things it should be breaking them now? All So you are currently only getting the non-generic CompletedTask if you are manually using it rather than using async and await. |
The alternative would be to go a bit further with #24431 and drop However I do think anything that can't handle a |
It would certainly be possible for someone to depend on That said, I don't have a strong opinion about whether the savings of one static field and one allocation for the whole process is worthwhile here: I defer to @jkotas' expertise on that. |
Also means var task = MethodAsync();
if (ReferenceEquals(task, Task.CompletedTask))
{
// ... When used instead of var task = MethodAsync();
if (task.IsCompletedSucessfully)
{
// ... Will work in more instances; umm.... not that I've seen it hanging around in any pre-Core 2.0 legacy code... (when .IsCompletedSucessfully was introduced) https://github.com/aspnet/AspNetCore/blob/15fb5b9e83a99c810ab82716e1f82d4b9378e65a/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs#L762-L765 😨 Probably should make a PR there also... |
That hurts me. |
I think this is a good change to take once we open master for .NET 5 (~3 weeks). Task has a lot of internal fields, so one more does not make things look that much worse. |
Replaced by #27437 |
Just the CompletedTask sharing from #24431
/cc @stephentoub @jkotas