Reduce websocket subscription dispatch and receive-loop overhead - #678
Open
maedula wants to merge 2 commits into
Open
Reduce websocket subscription dispatch and receive-loop overhead#678maedula wants to merge 2 commits into
maedula wants to merge 2 commits into
Conversation
added 2 commits
July 16, 2026 15:55
…comingMessageDispatcher Every active GraphQL subscription independently subscribed to the shared incoming websocket message stream and filtered it with its own Where(response.Id == myId) predicate, so the per-message cost scaled with the number of concurrent subscriptions instead of being constant. IncomingMessageDispatcher keeps a single subscription to the shared stream and routes each message directly to its owner via a dictionary lookup.
…sync pump Observable.Defer(() => GetReceiveTask().ToObservable()).Repeat().Catch(...).Publish() allocated a SlowTaskObservable (bridging via Task.ContinueWith) and re-entered Repeat's TailRecursiveSink trampoline for every single incoming websocket message. Profiling showed this Rx plumbing, not application logic, was the largest CPU and allocation cost in the receive path. A plain async while loop pushing into a Subject gives the same hot/multicast/run-until-cancelled semantics without the per-message Rx bridging overhead.
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
Wheresubscriptions on the shared incoming stream with one ID-keyed dispatcherTask -> Observable -> Repeatreceive chain with an owned async receive pumpThis changes incoming message routing from broadcasting every message to every active operation to a single dictionary lookup, and removes the Rx task-bridging objects allocated for each received message.
Validation
dotnet test tests/GraphQL.Integration.Tests/GraphQL.Integration.Tests.csproj -c Releasedotnet build src/GraphQL.Client/GraphQL.Client.csproj -c Release -f netstandard2.0