Repository navigation
Drop the second comma search from Content-Length folding - #88
Merged
Merged
Conversation
ContentLengthFields.Fold splits each Content-Length field at its commas and trims every element before it parses it, so ParseContentLengthDigits never sees a comma. It still searched for one and trimmed again, left over from when it was handed the whole field value. Fold is its only caller. Rename it ParseDecimalDigits and drop the comma handling; the saturating digit loop is unchanged. Inline ScanFramingFields, the scan both framing helpers share.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #74, #75 and #77. I held it back until they merged, because all three edit the same function.
Since #77,
ContentLengthFields.Foldsplits each Content-Length field at its commas and trims each element. Only then does it callBodyFramingDetector.ParseContentLengthDigits. That function still searched the element for a comma and trimmed it again, left over from when it was handed the whole field value.Foldis its only caller, so that second search never finds anything.ParseContentLengthDigitsbecomesParseDecimalDigits, without the comma handling. The saturating digit loop from Saturate oversized Content-Length at long.MaxValue instead of no body #75 is unchanged.ScanFramingFields, the private scan both framing helpers share, is markedAggressiveInlining.Behaviour is unchanged: the 1,125 tests pass without edits.
Performance
I ran an in-process A/B test, alternating the builds round by round on one pinned P-core (i9-14900K, .NET 10). It ran 30 rounds, twice. Medians in ns/op:
DetectBodyFramingDetectResponseBodyFramingContentLengthBodyReader.ParseContentLengthThat recovers about half of what the framing helpers cost after the hardening PRs. The rest is work #77 added on purpose: every element of a Content-Length list is parsed and compared. Main measured against itself stayed within 3%, except one
ParseContentLengthrun at +17%.GenHTTP doesn't call these helpers, so only direct callers see this.