perf: use byteLength property for binary body chunks#5126
Merged
trivikr merged 1 commit intonodejs:mainfrom Apr 30, 2026
Merged
perf: use byteLength property for binary body chunks#5126trivikr merged 1 commit intonodejs:mainfrom
trivikr merged 1 commit intonodejs:mainfrom
Conversation
Assisted-by: openai:gpt-5.5 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Member
Author
|
Benchmarks benchmark avg (min … max) p75 / p99 (min … top 1%)
---------------------------------------------- -------------------------------
• body writer chunk length
---------------------------------------------- -------------------------------
Buffer.byteLength(buffer) 9.21 ns/iter 9.12 ns █
(9.05 ns … 38.91 ns) 12.80 ns █
( 0.10 b … 57.16 b) 0.15 b █▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
buffer.byteLength 362.41 ps/iter 356.20 ps █
(325.44 ps … 14.06 ns) 386.47 ps █
( 0.09 b … 32.11 b) 0.09 b ▁▁▁▁▁▁▁▅▁▁█▁▁▂▁▁▁▁▁▁▁
Buffer.byteLength(uint8Array) 9.60 ns/iter 9.35 ns █
(9.30 ns … 47.80 ns) 14.59 ns █
( 0.10 b … 56.11 b) 0.14 b █▃▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
uint8Array.byteLength 396.28 ps/iter 396.73 ps █
(366.21 ps … 14.03 ns) 416.99 ps █ █
( 0.09 b … 84.19 b) 0.09 b ▁▁▁▁▁▁▁▁█▁▁▁█▁▁▁▂▁▁▁▁
Buffer.byteLength(string) 2.54 µs/iter 2.54 µs █ ▅
(2.52 µs … 2.60 µs) 2.59 µs █▇█
( 0.10 b … 1.12 b) 0.13 b ███▇▄▇▄▇▄▆▄▄▁▁▁▁▁▁▁▁▃
• body writer chunk length helper
---------------------------------------------- -------------------------------
previousChunkLength(buffer) 12.99 ns/iter 12.93 ns █
(12.87 ns … 36.76 ns) 14.23 ns ▄█
( 0.09 b … 44.11 b) 0.17 b ██▁▁▁▁▁▁▁▁▁▂▁▁▁▁▁▁▁▁▁
currentChunkLength(buffer) 399.13 ps/iter 396.73 ps █
(366.21 ps … 14.01 ns) 417.24 ps █
( 0.09 b … 44.73 b) 0.09 b ▁▁▁▁▁▁▁▁▆▁▁▁█▁▁▁▂▁▁▁▁
previousChunkLength(uint8Array) 9.30 ns/iter 9.26 ns █
(9.22 ns … 24.05 ns) 10.66 ns ██
( 0.10 b … 56.10 b) 0.15 b ██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
currentChunkLength(uint8Array) 1.96 ns/iter 1.94 ns █
(1.92 ns … 15.85 ns) 2.04 ns █
( 0.09 b … 52.10 b) 0.11 b ▁▁▃█▁▅▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
previousChunkLength(string) 2.55 µs/iter 2.54 µs █▂
(2.52 µs … 2.70 µs) 2.69 µs ██
( 0.10 b … 2.01 b) 0.14 b ██▇▅▁▂▁▂▁▁▂▃▁▅▁▁▁▁▁▁▂
currentChunkLength(string) 2.53 µs/iter 2.54 µs █ ▂
(2.53 µs … 2.60 µs) 2.56 µs █▇▃█
( 0.10 b … 0.74 b) 0.12 b ████▁▂▁▂▅▄▁▄▄▂▁▁▁▂▂▅▂ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5126 +/- ##
=======================================
Coverage 93.14% 93.14%
=======================================
Files 110 110
Lines 36117 36117
=======================================
Hits 33642 33642
Misses 2475 2475 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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...
Improves HTTP/1 body writer chunk-size handling for binary chunks
Rationale
AsyncWriter.write()usedBuffer.byteLength(chunk)for every body chunk.For
BufferandUint8Arraychunks,chunk.byteLengthis cheaper and avoids the string-oriented logic inBuffer.byteLength(). String chunks still needBuffer.byteLength()to preserve byte-accurate content-length and chunked framing behavior.Changes
chunk.byteLengthwhen body writer chunks areUint8Arrayinstances, includingBuffer.Buffer.byteLength(chunk)for string chunks and invalid non-binary values.Features
N/A
Bug Fixes
N/A
Breaking Changes and Deprecations
N/A
Status
Assisted-by: openai:gpt-5.5