Repository navigation
perf: coalesce queued updates into one flush - #1500
Merged
Merged
Conversation
Each update was flushed on its own, costing one write syscall per update and subscriber. Write every update queued when the batch starts, then flush once. Updates queued later wait for the next batch, and a batch ends early on a disconnection, a shutdown, a drain or the disconnection time, so the subscribe loop handles them without delay. Check the write deadline and arm the dispatch deadline before each update, after serializing it: a long batch must not be cut off by a single dispatch timeout, nor write past exp. The flush keeps the last update's dispatch deadline. Near the write deadline, the dispatch deadline is now capped at it instead of left unset, which would keep a previous update's shorter deadline armed. Medians of 3 runs on Linux (arm64, 10 CPUs): - replaying 900 updates to 1,000 subscribers with Bolt: 0.59 s and 3 CPU seconds -> 0.24 s and 1 - broadcasting to 1,000 URL pattern subscribers (200,000 deliveries/s): delivery p99 12.8-20 ms -> 9.3-11 ms Exact-topic fan-out throughput and CPU are unchanged.
dunglas
force-pushed
the
perf/coalesce-sse-writes
branch
from
December 1, 2026 17:22
b00036d to
2c64fb8
Compare
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.
Each update was flushed on its own: one write syscall per update and subscriber. Profiling a hub broadcasting to 1,000 URL pattern subscribers puts 95% of its CPU in these writes.
The subscriber loop now writes every update already queued when a batch starts, then flushes once. Updates queued later wait for the next batch. A batch also ends early when the request is canceled, the hub shuts down, a drain starts or the disconnection time is reached, so the subscribe loop handles these without delay.
Deadlines:
prepareWrite, now shared withwrite): a batch never writes past the token'sexp, even behind a wrapper that re-arms the connection deadlinedispatch_timeout, so a long batch is not cut off by a single timeout, and a client that stopped reading is still cut off after one timeoutMeasured on Linux (arm64, 10 CPUs), medians of 3 runs, no lost delivery:
Exact-topic fan-out throughput and CPU are unchanged. On macOS, where concurrent socket writes contend in the kernel, the broadcast drops from 37 to 15 CPU seconds over 10 s.