Repository navigation
perf(stream): compact relay state and reuse output identities - #478
Merged
Merged
Conversation
added 12 commits
November 3, 2026 09:14
Sync the decoder copy with the receiver: reserve an upper bound for an uncompressed snapshot instead of growing it while many connections hand over their state together.
timtofan
requested review from
Joypaul11,
deniszh,
emadolsky and
grzkv
as code owners
November 3, 2026 08:40
emadolsky
approved these changes
Nov 4, 2026
deniszh
approved these changes
Nov 4, 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.
Depends on #477
Why
Large relays can retain millions of input IDs across roughly 85 producer connections. Interface slots, duplicated route allocations, per-socket compression scratch, and repeated output-name lookup consume memory and CPU. Overlapping reload processes make retained-state cost especially significant.
Architecture
The listener uses compact pinned-name slots in 128-entry pages, with direct references, predictors, and bitmaps. Admission charges actual page/vector and staging capacity before allocation. Ordinary routes live inside shared name entries; complex rewrite/continued routes retain bounded independent plans.
Each shared input identity also owns an aligned atomic output token. Single-path records borrow it and retain the owning allocation; output generation checks validate reuse. Failed admission remains record-local, and multi-path records keep independent hints. CPU-bounded pools share output compression and frame workspaces; per-connection wire dictionaries remain separate. Handoff writes bounded STATE frames instead of building a whole extra snapshot.
These compact binding, streaming snapshot, and workspace hooks extend the explicitly documented maintained codec delta. Publication of a shared codec or receiver adoption allows that delta to be removed. Wire v1, sender peer estimates, host selection, and delivery guarantees retain their existing contracts.
Before / after
Usage
Existing stream listeners and output senders activate these paths automatically. The ordinary decoder API remains available.
docs/stream-input.mddocuments the opt-in synthetic memory and CPU models, including the producer-pool fixture, scratch paths, and accounting limits. Keep process memory headroom for reload overlap.Validation
Go 1.27.0 with vendor mode: build, vet, serialized full tests, golangci-lint v2 with the upstream configuration, and race tests on every changed Go package. Tests cover compact/generic decoder parity, admission cleanup, snapshot bytes, shared token lifetime, stale tokens, multi-path routing, and workspace concurrency. External receiver and large process benchmarks are separate opt-in checks; no production measurements are claimed here.