-
-
Notifications
You must be signed in to change notification settings - Fork 23.7k
Use Span to reduce allocations in HTTPClientTCP::poll
#104929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
98317fc to
5159a8a
Compare
ede3568 to
26988b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code wise this looks good to me!
Unfortunately, I don't have any insight on the http client, and whether this function needs to be fast.
I'd like to see either a benchmark showing a practical improvement, or a review from networking folks.
| const int index = std::size(transferEncodingLabel) - 1; | ||
| Span<char32_t> sp = Span<char32_t>(s.ptr() + index, s.length() - index); | ||
| sp = String::strip_edges_span(sp, true, true); | ||
| if (String("chunked") == sp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't need to allocate a String. However, my equality operator PR is still outstanding, so I think it's acceptable for the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it would be better to not have to construct the string, but we can't right now. We can update this if your PR is merged.
HTTPClientTCP::poll
Spotted during this PR.
Used span to avoid some substring allocations. Avoid find that could be done at compile time. Remove useless push_back, parse_utf8 does not have to be 0 terminated.
Extracted strip_edges logic into a static function, to be able to call it with span and strings (without the need to allocate a string).
The name may not be very good, but naming it strip_edges brought conflict with Variant, probably because the name is bound.
Maybe we should come up with a long term solution for this because I guess the need will arise with other functions (applying strings functions to span created from strings).