dotnet / dotnet/aspnetcore

HttpRequestStream & DuplexPipeStream don't amortize their ValueTask ReadAsync calls

Open
#11,940 0 comments 1 reaction 0 assignees View on GitHub
affected-very-few area-networking enhancement Perf severity-nice-to-have
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

In usage a HttpRequestStream & DuplexPipeStream normally has very many ReadAsync calls made on them. (Use case WebSockets/SignalR over TLS)

Using the ValueTask overloads for these Streams read allocates a AsyncStateMachineBox per read (when data is not immediately available)

![image](https://user-images.githubusercontent.com/1142958/60764465-56904980-a082-11e9-9be2-3f217b4a1cb2.png)

However it could use `TryRead` for the sync-path and allocating a IValueTaskSource object the first time that fails to back the async read, and then reuse it each time the read needs to go async again.

Related https://github.com/dotnet/corefx/issues/39258

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.