Repository navigation
dagql, core: memoize the Module results a call frame references - #14920
Merged
Merged
Conversation
tiborvass
approved these changes
Oct 28, 2026
sipsma
force-pushed
the
sipsma/dagql-module-ids-memo
branch
from
October 28, 2026 22:04
3f5941a to
e033e8e
Compare
core.Query.ModDepsForCall walked the receiver's whole call graph on every handle load (node(id:)) to find the Module results it references. For a package exec in a per-package Go build, that graph reaches into every imported package's graph, and each frame visited took the cache's read lock. The cache now answers which Module results a frame references (Cache.ModuleResultIDs), memoized on the frame and built from the answers of the frames it references. A stored frame's own fields don't change, but a referenced result's frame can be replaced by an equivalent one that references different Module results, so each memo holds for the frame generation it was computed in; replacing a frame starts a new generation. Each call records every frame it computes and reuses that for the rest of the call, so it computes each frame at most once, as WalkResultCall visits each frame once. Without that, frames above a cycle (kept out of the memo, since their answer would miss their ancestors' modules) and frames whose memo a call of another generation overwrote would be recomputed on every further path to them, exponentially in how much of the graph is shared. The call also stops with the request's error once the request is canceled. Signed-off-by: Erik Sipsma <[email protected]>
ModuleResultIDs must return what WalkResultCall finds, in the same order, including inline and zero-ID references and on shared graphs memoized out of order. A referenced frame's replacement must invalidate memos, including one computed before the replacement and stored after it; a cycle must store no partial memo; and lookups must stay correct while frames are replaced. A call must compute each frame once: under a cycle, while calls of other generations overwrite the memos, and when one such overwrite lands between two paths to the same frame. A canceled call must stop. Signed-off-by: Erik Sipsma <[email protected]>
moduleResultIDs carried the walk over a frame's references as closures, which put it over gocyclo's limit. The walk of one frame's references now lives on moduleIDsFrameWalk; what it computes and in what order are unchanged. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/dagql-module-ids-memo
branch
from
October 28, 2026 22:30
e033e8e to
1d40e9c
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.
Every load of an object by its ID (
node(id:)) worked out which modules the object depends on by walking its whole call graph. A Go build with one exec per package makes thousands of these loads over deep graphs, and that walk was most of each load's cost. This change memoizes the answer on each call frame, so repeated loads reuse it.What changes for users
An edit of a package deeper in the tree shows the same: −24% slot hold per cached package, about −0.18 s for its pass.
The whole edit build is ~9–12 s, so ~0.13 s is within its run-to-run spread.
First builds don't change: 31.2 s at the median with the change, against 32.7 s without, 5 each. The engine's peak memory is unchanged: 1,153–1,256 MB with it, against 1,189–1,231 MB.
Nothing else changes for users. The same modules are found, in the same order, so the schema each load uses is unchanged.
How
dagql:Cache.ModuleResultIDsreturns the result IDs of the Module results a call frame's graph references, in the orderWalkResultCallvisits them.WalkResultCallvisits a frame once. It records every frame it computes, including those it can't memoize, and reuses them for the rest of the call.core.Query.ModDepsForCalluses it instead of walking. Loading the modules for the requesting session's schema still happens on every load, as before.A stall found before this PR, and fixed
An earlier version of this change sometimes stalled a first build: one took 132 s instead of ~30, with the engine busy throughout.
Tests
dagql/result_call_module_ids_test.go:WalkResultCall's, in the same order, including inline and zero-ID references, and on 200 random shared graphs memoized out of order.They run under
-racewith dagql's other tests.