Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Change some internal async Task methods to be async ValueTask #40527

Merged
merged 1 commit into from
Oct 10, 2019

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Aug 23, 2019

Requires dotnet/coreclr#26310.

We have some internal and private async Task methods that are only ever awaited (or returned out to callers via public API). Today there's no benefit and a small downside to making them async ValueTask methods, so we've kept them as async Task. However, if we end up changing the implementation of async ValueTask to pool underlying objects, there becomes a potential benefit to using async ValueTask for these instead of async Task. This PR changes those in a variety of libraries where we care more about performance and allocations. There are likely a few more methods we'd want to convert based on profiling, but I believe this represents the bulk of them.

This should only be merged if dotnet/coreclr#26310 is merged and profiling determines that these changes are worthwhile.

cc: @benaadams

@benaadams
Copy link
Member

Is unhappy?

src/System.Net.Security/src/System/Net/Security/SslStream.cs(768,13): error CS0012: 
The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.
src/System.Net.Security/src/System/Net/Security/SslStream.cs(768,13): error CS0012: 
The type 'IAsyncActionWithProgress<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.
src/System.Net.Security/src/System/Net/Security/SslStream.cs(768,13): error CS0012: 
The type 'IAsyncOperation<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.
src/System.Net.Security/src/System/Net/Security/SslStream.cs(768,13): error CS0012: 
The type 'IAsyncOperationWithProgress<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.
src/System.Net.Security/src/System/Net/Security/SslStream.cs(806,20): error CS0029: 
Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'System.Threading.Tasks.ValueTask'

@stephentoub stephentoub force-pushed the tasktovaluetask branch 2 times, most recently from 7e77d37 to faf9bca Compare August 26, 2019 02:34
@stephentoub
Copy link
Member Author

Is unhappy?

Fixed. The System.Net.Security UnitTests build in some product source along with a fake that needed to be tweaked.

@stephentoub stephentoub changed the title [WIP] Change some internal async Task methods to be async ValueTask Change some internal async Task methods to be async ValueTask Aug 26, 2019
@stephentoub stephentoub added the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 26, 2019
We have some internal and private `async Task` methods that are only ever `await`ed.  Today there's no benefit to making them `async ValueTask` methods, so we've kept them as `async Task`.  However, if we end up changing the implementation of `async ValueTask` to pool underlying objects, there becomes a potential benefit to using `async ValueTask` for these instead of `async Task`.  This PR changes those in a variety of libraries where we care more about performance and allocations.  There are likely a few more methods we'd want to convert based on profiling, but I believe this represents the bulk of them.
@stephentoub stephentoub removed the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Oct 9, 2019
@stephentoub stephentoub marked this pull request as ready for review October 9, 2019 21:16
@stephentoub
Copy link
Member Author

I'd like to go ahead with this PR now. It doesn't make any of the macro scenarios I looked at worse, and having it in will enable better validating the corresponding runtime change's impact.

@stephentoub stephentoub added this to the 5.0 milestone Oct 9, 2019
@stephentoub stephentoub merged commit 97d9fb9 into dotnet:master Oct 10, 2019
@stephentoub stephentoub deleted the tasktovaluetask branch October 10, 2019 10:04
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…/corefx#40527)

We have some internal and private `async Task` methods that are only ever `await`ed.  Today there's no benefit to making them `async ValueTask` methods, so we've kept them as `async Task`.  However, if we end up changing the implementation of `async ValueTask` to pool underlying objects, there becomes a potential benefit to using `async ValueTask` for these instead of `async Task`.  This PR changes those in a variety of libraries where we care more about performance and allocations.  There are likely a few more methods we'd want to convert based on profiling, but I believe this represents the bulk of them.

Commit migrated from dotnet/corefx@97d9fb9
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants