Skip to content

Opt pooled async methods out of runtime async#128943

Draft
jakobbotsch wants to merge 4 commits into
dotnet:mainfrom
jakobbotsch:opt-out-pooled
Draft

Opt pooled async methods out of runtime async#128943
jakobbotsch wants to merge 4 commits into
dotnet:mainfrom
jakobbotsch:opt-out-pooled

Conversation

@jakobbotsch
Copy link
Copy Markdown
Member

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

We do not have a replacement for this concept in runtime async (yet).
For now opt these methods out of runtime async.
Copilot AI review requested due to automatic review settings June 3, 2026 12:41
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines +2318 to +2320
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs">
<Link>Common\Runtime\CompilerServices\RuntimeAsyncMethodGenerationAttribute.cs</Link>
</Compile>
Comment on lines +6 to +10
[AttributeUsage(AttributeTargets.Method)]
internal sealed class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute
{
public bool RuntimeAsync => runtimeAsync;
}
@teo-tsirpanis
Copy link
Copy Markdown
Contributor

I would expect that a custom async method builder would imply opting out of runtime async by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants