Repository navigation
Add configurable concurrent resolution of subscription items - #1833
Open
tpham-mysten wants to merge 1 commit into
Open
tpham-mysten wants to merge 1 commit into
tpham-mysten wants to merge 1 commit into
Conversation
Subscription payloads are resolved strictly serially (StreamExt::then in the derive), so a subscription resolving DB-backed fields does one backend round trip per payload with no DataLoader batching across payloads. Add a subscription_resolution_concurrency knob to SchemaBuilder (default 1, i.e. serial, so existing behavior is unchanged). When set > 1, the derive resolves up to N subscription items concurrently with buffered(N) (output order preserved via FuturesOrdered), so their DataLoader reads coalesce the same way a list's do within a payload. A server opts in with Schema::build(...).subscription_resolution_concurrency(n). The one correctness fix it needs: all items shared a single QueryEnvInner.errors sink drained per-item, which only works serially. Move errors from Arc<QueryEnvInner> onto QueryEnv and add fork_errors() so each concurrently-resolved item gets its own sink. Field shadowing keeps every existing errors read site unchanged, and queries/mutations never fork, so their behavior is untouched.
tpham-mysten
force-pushed
the
upstream-subscription-concurrency
branch
from
July 31, 2026 16:26
baaa022 to
6530206
Compare
tpham-mysten
marked this pull request as ready for review
July 31, 2026 16:27
This branch has not been deployed
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.
Description
Subscription payloads are resolved one at a time: the selection set for each
yielded value is fully resolved before the next value is polled from the stream.
When resolving a payload involves async work (for example, fetching nested
fields from a database or another service), that work is serialized across
payloads, so a fast-producing subscription ends up bottlenecked on resolving a
single payload at a time.
This adds a schema-level option to resolve multiple subscription payloads
concurrently while preserving output order:
The default is
1, which keeps the current behavior of resolving one payload ata time, so the change is fully backwards compatible.
Internally the subscription resolver switches from
StreamExt::then(serial) toStreamExt::mapfollowed byStreamExt::buffered(n), so up tonpayloadsresolve in flight while results are still yielded in stream order. Each in-flight
payload resolves against its own error sink, so concurrent payloads do not drain
one another's errors.
Output ordering is unchanged, and a test covers that N payloads resolve
concurrently and are still delivered in order.
This mirrors amnn/async-graphql#2,
which has already been reviewed; opening here to upstream it.