Repository navigation
perf(sse): split only the newly decoded text in stream line readers - #10118
Merged
waleedlatif1 merged 1 commit intoNov 17, 2026
Merged
Conversation
The SSE and NDJSON line readers appended each decoded chunk to the pending line and re-split the whole buffer, so one large event (a block output of a few MB in the run stream) was rescanned and re-flattened on every chunk: quadratic in the event size. The pending remainder never holds a newline, so splitting just the new text and prefixing the first piece gives the same lines.
|
@b84330808 is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
[Medium impact] The PR appears safe to merge. SummarySpeeds up five SSE and NDJSON read loops across four files by splitting only newly decoded text.
Reviews (1) · Last reviewed commit: "perf(sse): split only the newly decoded ..." · Reviewed by Greptile |
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.
Summary
The SSE and NDJSON line readers append each decoded chunk to the pending line and then split the whole buffer again. When one event is large, for example a block output of a few MB in the run stream (
block:completedcarriesoutputanddisplay.output,execution:completedcarriesoutputandfinalBlockLogs), every chunk rescans and re-flattens the whole pending event. Reading it is quadratic in its size.The pending remainder never contains a newline, so splitting only the new text and prefixing its first piece with the remainder gives exactly the same lines. Same change in
readSSELines(lib/core/utils/sse.ts), the two NDJSON readers in the Mothership block handler, and the CLI'sreadNdjsonandsseData.Type of Change
Testing
sse.test.ts, and sim-cliworkflow-run-follow.test.tsandchat.test.tspass unchanged (57 tests). Biome is clean on the touched files.readSSELinesgave identical lines in 3000 cases, and the NDJSON loop forms matched in 5000.fetchthroughreadSSEEvents. Node 24.15 on Windows 11, chunks arrive at 64 KB, 7 alternating rounds, median (min to max):In Chromium the reader gets bigger chunks, so the gain is smaller. With the server pacing delivery at about 2 to 8 MB/s, main-thread time spent in the reader went from 187 to 31 ms for a 2 MB output and from 320 to 43 ms for 4 MB. Wall time stayed the same because the network bounds it.
Checklist