Opt pooled async methods out of runtime async#128943
Conversation
We do not have a replacement for this concept in runtime async (yet). For now opt these methods out of runtime async.
|
Tagging subscribers to this area: @dotnet/area-meta |
There was a problem hiding this comment.
Pull request overview
This PR introduces an internal opt-out mechanism for “runtime async” generation and applies it to a set of pooled-async (PoolingAsyncValueTaskMethodBuilder*) methods across core libraries and key networking/IO components to avoid regressions when runtime async is enabled.
Changes:
- Add
RuntimeAsyncMethodGenerationAttribute(internal, shared source) to control runtime-async method generation. - Annotate selected pooled-async methods with
[RuntimeAsyncMethodGeneration(false)]in core IO, pipelines, and System.Net implementations. - Wire the shared attribute source into multiple library projects so the annotation is available at compile time.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs | Opts ReadAtLeastAsyncCore (pooled async) out of runtime async generation. |
| src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs | Opts ReadAsyncSlowPath / WriteAsyncSlowPath pooled async paths out of runtime async generation. |
| src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems | Includes the new shared attribute source in CoreLib (link path needs adjustment). |
| src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs | Opts key pooled async receive/buffering helpers out of runtime async generation. |
| src/libraries/System.Net.WebSockets/src/System.Net.WebSockets.csproj | Includes the shared attribute source file in the project. |
| src/libraries/System.Net.Security/src/System/Net/Security/SslStream.IO.cs | Opts pooled async TLS frame/read helpers out of runtime async generation. |
| src/libraries/System.Net.Security/src/System.Net.Security.csproj | Includes the shared attribute source file in the project. |
| src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RawConnectionStream.cs | Opts pooled async ReadAsync override out of runtime async generation. |
| src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs | Opts pooled async ReadBufferedAsyncCore out of runtime async generation. |
| src/libraries/System.Net.Http/src/System.Net.Http.csproj | Includes the shared attribute source file in the project. |
| src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj | Includes the shared attribute source file in the project. |
| src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs | Opts pooled async flush core out of runtime async generation (NET-only section). |
| src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs | Opts pooled async local core reader loop out of runtime async generation (NET-only section). |
| src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj | Includes the shared attribute source file for .NETCoreApp builds. |
| src/libraries/Common/src/System/Threading/AsyncOverSyncWithIoCancellation.cs | Opts pooled async work-item wrappers out of runtime async generation. |
| src/libraries/Common/src/System/Runtime/CompilerServices/RuntimeAsyncMethodGenerationAttribute.cs | Adds the shared internal attribute definition (minor implementation/style issues noted). |
| <Compile Include="$(CommonPath)System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs"> | ||
| <Link>Common\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs</Link> | ||
| </Compile> |
| [AttributeUsage(AttributeTargets.Method)] | ||
| internal sealed class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute | ||
| { | ||
| public bool RuntimeAsync => runtimeAsync; | ||
| } |
|
I would expect that a custom async method builder would imply opting out of runtime async by itself. |
cc @333fred, what's your opinion? |
|
It's not the way we specified it, but if that's something we need to do, we can take a look. |
|
I opened dotnet/roslyn#84061 to track this on the Roslyn side. For now I think we can manually opt these out in dotnet/runtime. |
We do not have a replacement for this concept in runtime async (yet) and ASP.NET is seeing some regression from that. For now opt these methods out of runtime async.
cc @BrennanConroy