mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-25 10:58:20 -10:00
* Several perf improvements/tweaks for SocketsHttpHandler - Chunked reads from buffer. We now process as much of the buffer as we can synchronously during ReadAsync, rather than returning once we hit the end of a chunk. For very small chunks that arrive quickly, this results in a huge perf increase, e.g. best case for the optimization, with lots of 1-byte chunks getting buffered together, it's now 10x faster. With 100-byte chunks buffered together, it's 2x faster. - Blitting byte[] to output for known headers. Rather than using WriteStringAsync to output all header names, we now use WriteBytesAsync for known headers, with the headers precomputed into byte[]s and cached. - Removed delegate/closure allocation from connection. We were accidentally closing over a cancellation token, resulting in an extra delegate and closure allocation in ConnectHelper. Also reduced the size of the EstablishSslConnectionAsync state machine by splitting the method in order to remove several arguments from being included. - Use Utf8Formatter for hex values. Switched from custom formatting of hex values to just use Utf8Formatter.TryFormat. - Avoid buffering in HttpConnection.CopyToAsync(Stream). This is used when we want to copy the whole source stream until EOF (e.g. for a Connection: close response), and thus we can skip the buffer and use the source stream's CopyToAsync directly. - Added a test to exercise various size chunks, line endings, ReadAsync vs CopyToAsync, etc. - Fix CopyToAsync cancellation handling. Even though we'll abort the connection when cancellation is requested, we still need to pass the token to the destination stream's WriteAsync to give it the opportunity to cancel. Also properly pass the buffer size through to the underlying stream's CopyToAsync where appropriate. - Small miscellaneous cleanup, like removing a few unused arguments from methods, fixing an assert to validate the right thing, etc. * Address PR feedback * Fix test on netfx Commit migrated from https://github.com/dotnet/corefx/commit/d5351fe933f0f4682ac465b656b2a438b076c24e