Reduce CurlHandler header parse allocations#6322
Conversation
|
Thanks, @justinvp!
PerfView has been updated with support for data captured on Linux: |
| return true; | ||
| } | ||
|
|
||
| private delegate char CharAt<T>(T key, int index); |
There was a problem hiding this comment.
Why not Func<T, int, char>? Similar question for the delegate below?
There was a problem hiding this comment.
I originally had Func<...> but changed them to concrete delegates to make the parameters more clear. Though, it doesn't matter all that much here. I can change it back to Func<...>s if you want.
There was a problem hiding this comment.
I always have a small preference for not introducing new delegate types, but if you think it leads to the code being more understandable, it's ok to leave as-is.
There was a problem hiding this comment.
Switched back to Func.
|
This is very nice, Justin. Thanks for doing this. A few nits, otherwise LGTM. |
|
Thanks, Steve and David. I added another commit that addresses the feedback (and a few other minor nits I noticed when going over the code again). I will squash before merging. I ran the following before/after on OS X: using (var client = new HttpClient())
{
for (int i = 0; i < 1000; i++)
{
client.GetAsync("http://httpbin.org/ip").GetAwaiter().GetResult().Dispose();
}
Console.WriteLine(GC.CollectionCount(0));
}Before: 4 I suppose if I increased the iterations we might see a more dramatic drop in Gen0 GCs. |
|
This is great, Thanks @justinvp |
|
Test Innerloop CentOS7.1 Debug Build and Test please |
Use existing known header and reason phrase instances instead of always allocating new strings and avoid unnecessary intermediate string allocations.
6a27957 to
0291b44
Compare
|
We definitely want to be using Latin1 encoding ( I have found inconsistencies between libcurl and WinHTTP with how WinHTTP handles invalid chars. libcurl doesn't do much validation at all. It mostly just passes each header line to the header callback and in our callback we don't add much validation ourselves. For example, WinHTTP fails if a null char is in a header value, but libcurl doesn't complain (nor do we). I'll open a separate PR soon (with tests) to address this. Let me know if the changes in this PR look good and I'll squash into a single commit. |
If you have time, it would be a good datapoint to get similar test results on validation from .NET Framework (Desktop) using HttpClient (HttpClientHandler). That uses the original managed sockets stack. |
Thanks!
Sounds good. Thanks. |
LGTM. No need to squash; the two commits is fine. |
Reduce CurlHandler header parse allocations
Reduce CurlHandler header parse allocations Commit migrated from dotnet/corefx@0d639c3
Use existing known header and reason phrase instances instead of always allocating new strings (similar to #3199 for WinHttpHandler) and avoid unnecessary intermediate string allocations.
cc: @stephentoub, @kapilash, @davidsh
(@stephentoub, is there a good way to profile the allocations for a before/after comparison on Unix?)
Note: I only tested this on OS X as I didn't have a Linux environment readily available; relying on CI for the other *nixes.