Skip to content

Drop the second comma search from Content-Length folding - #88

Merged
MDA2AV merged 1 commit into
mainfrom
perf/content-length-fold
Nov 3, 2026
Merged

MDA2AV merged 1 commit into
mainfrom
perf/content-length-fold

Conversation

@MDA2AV

@MDA2AV MDA2AV commented Nov 3, 2026

Copy link
Copy Markdown
Member

Follow-up to #74, #75 and #77. I held it back until they merged, because all three edit the same function.

Since #77, ContentLengthFields.Fold splits each Content-Length field at its commas and trims each element. Only then does it call BodyFramingDetector.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. Fold is its only caller, so that second search never finds anything.

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:

main before #74 main now this PR
DetectBodyFraming 11.6–11.8 14.5–14.7 12.9–13.1
DetectResponseBodyFraming 13.0–13.2 14.8–14.9 12.9–13.0
ContentLengthBodyReader.ParseContentLength 9.5 12.7–13.2 11.1

That 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 ParseContentLength run at +17%.

GenHTTP doesn't call these helpers, so only direct callers see this.

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.
@MDA2AV
MDA2AV merged commit 8c03228 into main Nov 3, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant