HttpRequestStream & DuplexPipeStream don't amortize their ValueTask ReadAsync calls
Open
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)

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
Assessment
This issue has not been assessed yet.