Repository navigation
Conversation
emitBodyDataEvents concatenated each incoming chunk onto the pending batch, copying the whole batch again every time. At high throughput a 20ms batch grows to several MB from 64KB chunks, so this cost was quadratic: a 200MB passthrough download dropped from ~1.5GB/s to ~340MB/s just from having a body-data listener. Collect chunks in a list and concatenate once per flush. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
emitBodyDataEventsappends each incoming chunk to the pending batch withBuffer.concat, which copies the whole batch again for every chunk. With fast bodies a 20 ms batch grows to several MB from 64 KB chunks, so the cost is quadratic in batch size.On localhost, a 200 MB passthrough download runs at ~1.5 GB/s with no listeners but ~340 MB/s as soon as anything listens for
response-body-data. This collects the batch's chunks in an array and concatenates once per flush; with a listener the same download runs at ~1.6 GB/s.maxBodySize: 64 KB, 3 runsresponse-body-datalistenerEvents, timestamps and
isEndedare unchanged. Added a test that streams 2000 small chunks faster than the batch interval and checks the events reassemble to the exact body with one ended event. The Node test suite passes (846 passing, 2 pending); I haven't run the browser tests, but this code is server-side only.🤖 Generated with Claude Code