Skip to content

Opt pooled async methods out of runtime async#128943

Merged
jakobbotsch merged 6 commits into
dotnet:mainfrom
jakobbotsch:opt-out-pooled
Jun 10, 2026
Merged

Opt pooled async methods out of runtime async#128943
jakobbotsch merged 6 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 thread src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems Outdated
@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.

@jakobbotsch

Copy link
Copy Markdown
Member Author

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

cc @333fred, what's your opinion?

@333fred

333fred commented Jun 4, 2026

Copy link
Copy Markdown
Member

It's not the way we specified it, but if that's something we need to do, we can take a look.

Copilot AI review requested due to automatic review settings June 8, 2026 10:34
@jakobbotsch jakobbotsch marked this pull request as ready for review June 8, 2026 10:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj Outdated
@jakobbotsch

Copy link
Copy Markdown
Member Author

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.

@VSadov

VSadov commented Jun 9, 2026

Copy link
Copy Markdown
Member

Do we have an issue to track making a runtime-async alternative or some other kind of follow up?

@VSadov

VSadov commented Jun 9, 2026

Copy link
Copy Markdown
Member

Actually, we may treat #129004 as a follow up workitem.

@VSadov VSadov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch jakobbotsch merged commit 8ac369d into dotnet:main Jun 10, 2026
160 of 162 checks passed
@jakobbotsch jakobbotsch deleted the opt-out-pooled branch June 10, 2026 12:53

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If AsyncMethodBuilder isn't respected by runtime async, shouldn't any method that has AsyncMethodBuilderAttribute be opted-out from runtime async (automatically - without needing to add [RuntimeAsyncMethodGeneration(false)]).

Edit: never mind - this was already discussed and tracked in dotnet/roslyn#84061

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 17, 2026
javiercn pushed a commit to dotnet/aspnetcore that referenced this pull request Jun 18, 2026
Port of dotnet/runtime#128943. Runtime async does not yet have a replacement for the pooled async method builder, so opt these methods out to avoid regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

8 participants