perf(client): parse h1 content-length statelessly#5124
Merged
mcollina merged 1 commit intonodejs:mainfrom Apr 30, 2026
Merged
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
7 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5124 +/- ##
==========================================
- Coverage 93.14% 93.13% -0.01%
==========================================
Files 110 110
Lines 35898 36109 +211
==========================================
+ Hits 33436 33629 +193
- Misses 2462 2480 +18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Assisted-by: openai:gpt-5.4 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Co-authored-by: tsctx <91457664+tsctx@users.noreply.github.com>
9576bfa to
676da7e
Compare
Member
Author
|
The benchmark improved after using for loop instead of array.reduce benchmark avg (min … max) p75 / p99 (min … top 1%)
------------------------------------------- -------------------------------
• parse content-length
------------------------------------------- -------------------------------
legacy 392.90 ns/iter 390.98 ns █
(376.62 ns … 1.64 µs) 434.16 ns ██▇▃ ▄
( 95.61 b … 310.16 b) 104.99 b ██████▆▅▂▃▂▂▃▁▁▁▂▁▁▁▁
stateless 38.53 ns/iter 38.28 ns █
(28.36 ns … 104.78 ns) 42.76 ns █
( 0.09 b … 80.11 b) 0.26 b ▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▃▁▁▁▁▁Marking this PR as ready for review. |
tsctx
approved these changes
Apr 27, 2026
Uzlopak
reviewed
Apr 27, 2026
Comment on lines
+458
to
+460
| for (let i = 0; i < buf.length; i++) { | ||
| this.contentLength = (this.contentLength * 10) + (buf[i] - 0x30) | ||
| } |
metcoder95
approved these changes
Apr 30, 2026
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.
This relates to...
N/A
Rationale
Avoid allocating and parsing
Content-Lengthresponse headers through strings.Since llhttp already validates
Content-Lengthas1*DIGITand rejects duplicate values, the H1 parser can parse the numeric value directly from the header buffer and use-1to represent absence.Changes
Content-Lengthdirectly from the header buffer.-1as the parser sentinel for missingContent-Length.Features
N/A
Bug Fixes
N/A
Breaking Changes and Deprecations
N/A
Status
Assisted-by: openai:gpt-5.4