Skip to content

querybuilder: run a query's receiver while its arguments get their IDs - #308

Merged
vito merged 2 commits into
vito:mainfrom
sipsma:sipsma/run-receiver-ahead
Nov 12, 2026
Merged

vito merged 2 commits into
vito:mainfrom
sipsma:sipsma/run-receiver-ahead

Conversation

@sipsma

@sipsma sipsma commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

A query can only be sent once every object argument in it is an ID, and getting an ID can mean running that object's own chain: for a Dagger module function, running the function. So in

wolfi.container(packages: [...]).withFile("/usr/local/bin/protoc-gen-go", goTool(...))

the arguments got their IDs first, at the same time as each other, and only then was the query sent, starting with wolfi.container. The receiver never overlapped its arguments, although neither depends on the other.

Now, when a call has an argument whose ID still needs a request, and its receiver is an object node(id:) can load, the chain up to the receiver runs at the same time as the arguments, ending in its ID. The rest of the query is then selected from that ID, the way a handle loaded after .sync is. With several such steps, the chain splits at the last one, and the part before it splits again, so every receiver runs ahead of the arguments after it. Everything else is sent whole, as before: a query whose arguments are already IDs, a chain off a mutation (it would run twice), and a receiver that may be null (it has no ID).

The first failure stops the other side and is the one returned. An argument whose ID request was cut short by that cancellation is no longer remembered as failed, so a later run of the same chain asks again.

Measured on a Dagger module that installs system packages while it builds four Go tools, on a fresh engine: 37.4 s before, 27.2 s after (medians of four).

A query can only be sent once every object argument in it is an ID, and
getting an ID can mean running that object's own chain, such as a call
into another module. So in a chain like

    slowBase.withFile(path: "/a", source: slowBuild)

the arguments got their IDs first, at the same time as each other, and
only then was the query sent, starting with slowBase. The receiver and
the arguments never overlapped, although neither depends on the other.

Now, when a step's arguments still need a request for their IDs, and
Dang marks the step's receiver as an object node(id:) can load, the chain
up to the receiver runs at the same time, ending in its ID. The rest of
the query is then selected from that ID. A query whose arguments are all
known IDs is sent whole, as before. So is a chain off a mutation, which
would run twice, and a receiver that may be null, which has no ID.

The first failure stops the other side and is the one returned. An
argument's marshal cut short by that cancellation is no longer kept, so
a later run of the same chain tries it again.

Signed-off-by: Erik Sipsma <[email protected]>
Two gaps in running a query's receiver ahead of its arguments:

- Only the first step whose arguments need requests split the chain. In
  base.withDir(src).withExec(...).withFile(build), withExec still waited
  for build. The chain now splits at the last such step, and the chain up
  to it, run through Execute too, splits again at the one before, so every
  receiver runs while the arguments after it resolve.

- A chain run again after its arguments got their IDs still split,
  adding a request: whether an argument needs one is now read from its
  marshalled state, not only from its value.

Signed-off-by: Erik Sipsma <[email protected]>

@vito vito left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, makes sense! A little bit trickier for sure, but easy to explain at a high level: the receiver is just another input, so it should be evaluated at the same time as the rest.

@vito
vito merged commit 683ac69 into vito:main Nov 12, 2026
8 checks passed
sipsma added a commit to dagger/dagger that referenced this pull request Nov 12, 2026
It brings vito/dang#308: a Dang query runs its receiver while its
arguments get their IDs, so code that chains calls with arguments built
from other calls no longer waits on each in turn.

Signed-off-by: Erik Sipsma <[email protected]>
sipsma added a commit to dagger/dagger that referenced this pull request Nov 13, 2026
It brings vito/dang#308: a Dang query runs its receiver while its
arguments get their IDs, so code that chains calls with arguments built
from other calls no longer waits on each in turn.

Signed-off-by: Erik Sipsma <[email protected]>
vito added a commit that referenced this pull request Nov 13, 2026
Hints for common mistakes get a section, with two errors as printed.
Faster Dagger modules, failed declarations reported once and the GraphQL
object list hint join the smaller changes. Go embedders learn that Dang no
longer needs cgo, and about LoadTreeSitter. The lede and sources cover
them, verified at 2918064.

Signed-off-by: Alex Suraci <[email protected]>
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.

2 participants