fix: prevent frontend OOM on high-throughput SSE streams#945
Merged
mhordynski merged 2 commits intodevelopfrom Feb 26, 2026
Merged
fix: prevent frontend OOM on high-throughput SSE streams#945mhordynski merged 2 commits intodevelopfrom
mhordynski merged 2 commits intodevelopfrom
Conversation
…oduce - Add EventBuffer class to decouple SSE stream from store updates - Batch text events into single set() call with pre-built flat string - Wrap MarkdownContent in content-visibility: auto for Chrome renderer
Contributor
Code Coverage SummaryDetailsDiff against mainResults for commit: 1ee4b1f Minimum allowed coverage is ♻️ This comment has been updated with latest results |
mhordynski
approved these changes
Feb 26, 2026
mkoruszowic
pushed a commit
that referenced
this pull request
Feb 27, 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.
Problem
Streaming large SSE responses causes the browser to consume excessive memory and crash. Each incoming SSE event triggered 3 separate
immer.produce()calls via set(), and the flush loop applied them individually per event. With thousands of events batched at 100ms intervals, this created tens of thousands of immutable state snapshots in a tight synchronous loop, preventing GC from reclaiming intermediate copies.Chrome was particularly affected due to V8 cons-string chains from repeated
+=through immer's Proxy setter, and Blink's eager layout computation for large DOM trees.Changes
historyStore.ts
.map().join("")outside immer, then applied with a single set() call — collapsing N×3 snapshots into 1 per batchMarkdownContent.tsx
<Markdown>in a<div>withcontent-visibility: auto— tells Chrome to skip layout/paint for off-screen content (Firefox already does this implicitly)Testing