Skip to content

Poll async fields and list items once in place - #1418

Merged
LegNeato merged 1 commit into
graphql-rust:masterfrom
LegNeato:async-polling
Nov 9, 2026
Merged

LegNeato merged 1 commit into
graphql-rust:masterfrom
LegNeato:async-polling

Conversation

@LegNeato

@LegNeato LegNeato commented Nov 1, 2026

Copy link
Copy Markdown
Member

This PR builds on #1417. Only its last commit is new.

  • The executor polls the future of each field and each list item once when it creates the future. Most futures complete at that point. Only pending futures go to a FuturesUnordered set. Every field and every list item used to go to a FuturesOrdered set, and each push allocated a task.
  • A queue behind the first pending field keeps the order of the fields. This also fixes the position of a __typename field after a pending field.
  • resolve_field_async() and the generated AsyncField::call() take the Arguments and the Executor by value, so the resolver future owns them. The executor used to keep them in an outer future of its own. Executor is now Copy.
  • One function completes field results for synchronous and asynchronous execution.

On the benchmarks of #1413 except introspection, asynchronous execution takes 6 to 39% less time than with #1417. Synchronous execution and introspection do not change. An asynchronous execution of 1000 objects with 6 fields each makes 19,067 allocations instead of 27,069.

Asynchronous execution pushed every field and every list item into a
`FuturesOrdered` set. Each push allocated a task, and each poll paid
for atomic waker operations. Most futures complete on their first poll,
so this cost bought nothing. The future of
`GraphQLValueAsync::resolve_field_async()` borrowed its arguments and
its executor, so the executor kept them in an outer future of its own.
The executor also added a `__typename` field to the object before the
pending fields, so `__typename` could appear out of order.

`resolve_field_async()` and the generated `AsyncField::call()` take the
`Arguments` and the `Executor` by value, so the resolver future owns
them. `Executor` is now `Copy`, because all its fields are shared
references or `Copy` values. The generated resolver extracts its
arguments inside its future.

The executor polls the future of a field or a list item once when it
creates the future. A completed field merges into the object, or waits
in a queue behind a pending field. A `__typename` field takes its place
in the queue too. Only pending futures go to a `FuturesUnordered` set,
and the queue keeps the order of the fields and items. A `null` item of
a non-`null` list stops the resolution of the remaining items, as in
synchronous execution. One function now completes field results for
both synchronous and asynchronous execution.

Asynchronous execution of a flat list of 1000 objects now makes 19,067
allocations instead of 27,069. On the benchmark operations except
introspection, asynchronous execution takes 6 to 39% less time.
Synchronous execution and introspection do not change.

New tests check the order of fields around a pending field, the order
of pending and ready list items, and the `null` list from a failing
ready item and a failing pending item. The manual implementations in
the tests use the new signature.
@LegNeato
LegNeato merged commit ff3bc50 into graphql-rust:master Nov 9, 2026
184 checks passed
@LegNeato
LegNeato deleted the async-polling branch November 9, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant