Several improvements to SocketsHttpHandler perf (dotnet/corefx#41640)
authorStephen Toub <stoub@microsoft.com>
Wed, 9 Oct 2019 01:22:47 +0000 (21:22 -0400)
committerGitHub <noreply@github.com>
Wed, 9 Oct 2019 01:22:47 +0000 (21:22 -0400)
commit108bf6bbf767c028d3714ad434e1d7c8e2068eac
treedd46815e893c8bd3f67dcfd72614e253cd20d669
parentc518055310888674f820f4198e4ef9d41e046f03
Several improvements to SocketsHttpHandler perf (dotnet/corefx#41640)

* Do not force-parse TryAddWithoutValidation headers in SocketsHttpHandler

When enumerating headers to write them out, do not force them to be parsed if the user explicitly asked for them not to be with "WithoutValidation".  If the key/values are incorrectly formatted, the request may end up being written incorrectly on the wire, but that's up to the developer explicitly choosing it.

* Revert HttpRequestHeaders.ExpectContinue optimization

Several releases ago, when we weren't paying attention to ExpectContinue, we optimized away the backing field for it into a lazily-initialized collection; that made it cheaper when not accessed but more expensive when accessed, which was fine, as we wouldn't access it from the implementation and developers would rarely set it.  But now SocketsHttpHandler checks it on every request, which means we're paying for the more expensive thing always. So, revert the optimization for this field.

* Avoid allocating a string[] per header

When we enumerate the headers to write them out, we currently allocate a string[] for each.  We can instead just fill the same array over and over and over.

Commit migrated from https://github.com/dotnet/corefx/commit/4d346a9ab7b6e619dae3784283acb87bb7a825c9
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/SocketsHttpHandler/HPack/HPackEncoder.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs
src/libraries/System.Net.Http/tests/UnitTests/HPack/HPackRoundtripTests.cs