Repository navigation
Resolve synchronous fields without futures in async execution - #1419
Merged
Merged
Conversation
Asynchronous execution created a future for every field, even if the resolver of the field and all resolvers below it were synchronous. Each such field paid for a boxed resolver future. The macros mark the fields without an `async` resolver with the new `Field::synchronous()` method. `RootNode` finds the types that resolve without awaiting when it builds the schema. Recursive types form cycles. The search therefore starts with all types as candidates and removes the candidates with an asynchronous dependency until no candidate changes. An interface field is synchronous if it is synchronous in all implementers. `Executor::resolve_async()` calls `GraphQLValue::resolve()` for values of synchronous types. The asynchronous executor resolves a synchronous field of a synchronous type in place with `GraphQLValue::resolve_field()`. The Book explains which fields resolve without futures. Asynchronous execution with synchronous resolvers now makes as many allocations as synchronous execution, and it runs as fast. A flat list of 1000 objects makes 4060 allocations instead of 19,067. On the benchmark operations except introspection, asynchronous execution with synchronous resolvers takes 13 to 67% less time. With `async fn` resolvers, scalars and enums resolve without futures, and execution takes up to 8% less time. New tests cover the detection of synchronous objects, interfaces, unions, cycles, and introspection types. Executor tests check that marked fields and synchronous types use the synchronous resolvers, and that other fields use the asynchronous resolvers.
LegNeato
force-pushed
the
sync-fast-path
branch
from
November 9, 2026 05:24
a53f880 to
2f4ae42
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.
This PR builds on #1418. Only its last commit is new. It is the last of the five stacked PRs that speed up execution.
asyncresolver with the newField::synchronous()method.RootNodefinds the types that resolve without awaiting when it builds the schema. An interface field is synchronous if it is synchronous in all implementers. Recursive types form cycles, so the search removes candidates until no candidate changes.GraphQLValue::resolve_field(), without a future.Executor::resolve_async()callsGraphQLValue::resolve()for values of synchronous types.With synchronous resolvers, asynchronous execution now makes as many allocations as synchronous execution, and it runs as fast. On the benchmarks of #1413 except introspection, it takes 13 to 67% less time than with #1418. With
async fnresolvers, scalars and enums resolve without futures, and execution takes up to 8% less time.The table compares
masterwith this PR and the four PRs before it. It shows the median time per request on an Apple M1 Pro. Synchronous execution takes 17 to 69% less time than onmaster, and asynchronous execution takes 20 to 87% less time. With synchronous resolvers and withasync fnresolvers,juniperis now faster thanasync-graphqlandapollo-compileron every operation.juniper_syncjuniperjuniper_async_fnasync_graphqlapollo_compilerminimalflat_listnested_listsstar_warsfragmentsintrospectionintrospection_without_one_of