Several allocation reductions in SocketsHttpHandler (#34724)
authorStephen Toub <stoub@microsoft.com>
Sat, 11 Apr 2020 18:21:37 +0000 (14:21 -0400)
committerGitHub <noreply@github.com>
Sat, 11 Apr 2020 18:21:37 +0000 (14:21 -0400)
commitc06810bf654e09f016fe34dd2b4ac31fb73370a1
tree9eb0f82dec286b0a19cf640899317432354b5ad8
parent54f34bbf56207ec80b05bae243333d2d05452527
Several allocation reductions in SocketsHttpHandler (#34724)

* Remove state machine allocation for SendWithNtConnectionAuthAsync

Just manually inline the tiny helper that's only used from one call site.

* Remove unnecessary HeaderStoreItemInfo allocations

For the common case of a raw string, let the dictionary store the raw string directly rather than always wrapping it in a HeaderStoreItemInfo.

* Cache Date and Server response header values

For Server, we expect it to be the same for every request on the same connection.

For Date, if we're making lots of requests in a high-throughput fashion, we expect many responses on the same connection to have the same value.

In both cases, we compare the received value against the last one received, and if it's the same, reuse the same string.
src/libraries/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpRequestHeaders.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionBase.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs
src/libraries/System.Net.Http/tests/UnitTests/HPack/HPackRoundtripTests.cs