Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Reuse HttpContext object per HTTP/1 connection and HTTP/2 stream #6424
PS: I looked at doing this in the default HttpContextFactory impl with a feature based approach but there's no place to store the HttpContext that isn't per request in other servers.
I'll try to get some perf results for allocations and throughput as well.
Here's a profile before all of the optimizations we've done (including a bunch from @benaadams):
I'm still waiting on dotnet/coreclr#21559 to be fixed to get an equivalent profile. Here's what I expect allocation wise:
That leaves us with the following allocations:
Here's what I got when looking at allocations with dotTrace's timeline view (thanks @pakrym)
We removed 35MB from the small object heap with this change.
As for the strings It's all headers and path:
That defeats the purpose. This change effectively makes DefaultHttpContext legacy without breaking existing consumers of it.
- Today in Kestrel, we reuse the IFeatureCollection per connection and per Http2Stream. This PR aims to take advantage of that same technique and affinitize the HttpContext and friends so that they are only allocated per connection. - ReusableHttpContext and friends mimic the functionality of DefaultHttpContext but is sealed and has no overridable methods.