Repository navigation
perf: faster module evaluation and collection listings - #15035
Merged
Merged
Conversation
Attaching a result whose call frame references inline calls resolves each referenced call to its attached result ID through resultIDForCall. That lookup only reads the e-graph, with the same lookupMatchForCallLocked a cache-hit lookup runs under the read lock, but it took egraphMu for writing. Converting a module object for a function call attaches every inline object it holds, so concurrent calls on a collection's items queued on this one lock: in a fresh listing of dagger/dagger's tests, 685 of the 715 collection getters in flight were waiting there. Take egraphMu for reading instead, through wcprof so a blocked acquisition is recorded like the other egraph lock waits. Signed-off-by: Erik Sipsma <[email protected]>
Converting a value for a module function asked each value's ModType for its TypeDef only to read the kind. That builds the typedef through dagql selections for every value converted, list elements included: millions of cached calls when a function receives a large collection. Every ModType already knows its kind, so expose it as Kind and switch on that in the SDK input conversion and in attaching stored field values. Signed-off-by: Erik Sipsma <[email protected]>
Every module function call converted its receiver for the SDK. A call on one collection item receives the whole collection, so the calls on one collection converted every item once per call: work quadratic in the collection's size. Each conversion also attached every inline stored object to the cache under the e-graph write lock, so concurrent item calls queued behind each other. The converted receiver depends only on the receiver result and the active result scope, not on the function called. Memoize its JSON per session, receiver result and artifact view through the cache's arbitrary values, so concurrent calls wait on the first conversion. The session is part of the key because conversion attaches inline objects to it. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
The Dang SDK rebuilds each object the engine passes in as a node(id:)
handle, but didn't record that ID. Returning or passing on such an
object then sent node(id:){id} to learn the ID it started from: one
HTTP request into the engine per value, queued behind other nested
clients' setup in a busy session.
The engine scopes the objects it passes in before encoding them, so
that query only ever hands back the same ID. Record it on the handle,
as Dang's own ID loader does.
Signed-off-by: Erik Sipsma <[email protected]>
A module can receive a recipe ID, e.g. for an argument whose result was released. node(id:) evaluates a recipe into a handle, and returning that handle is what the module did before; returning the recipe instead sends it through the replay check for module return IDs, which can refuse it. Signed-off-by: Erik Sipsma <[email protected]>
A command's stdout emits each write as a telemetry log record, which the frontend stores, parses through a virtual terminal and finally replays to the real stdout one record at a time. The listing's table goes through text/tabwriter, which writes every cell and every 8 bytes of padding separately, so a listing of a few thousand rows became tens of thousands of records. Buffer the listing, in every format, so it reaches stdout in 32 KiB writes. The bytes written are unchanged. Signed-off-by: Erik Sipsma <[email protected]>
A log record's body must be valid UTF-8, or the OTLP exporter's protobuf encoding rejects the whole batch. A fixed-size buffer can cut inside a multibyte character in a description, so pass the listing on in pieces of whole lines instead. Signed-off-by: Erik Sipsma <[email protected]>
Every call of a module's functions reads the git clients its governing dagger.toml declares, to key the call. For a module loaded from git or a directory that is three cached calls on its tree, which a persistable hit runs under the cache's write lock: about 4,400 times in one listing of a large module's tests. The tree is an immutable result, so the session now reads them once per tree result and module directory. A tree with an edited dagger.toml is another result, and result IDs are never reused. A local module still reads its host on every call, since the file there can change. Signed-off-by: Erik Sipsma <[email protected]>
…rations Signed-off-by: Erik Sipsma <[email protected]>
Resolving an image pinned by digest asked the registry for its root manifest twice: a HEAD to learn its type and size, then a GET for its content. The digest already names the root, and the GET follows either way, so the HEAD only adds a round trip. On a fresh engine that's one of the four sequential requests a resolve makes: about 60 ms against Docker Hub from us-east-1, and about 300 ms through mirror.gcr.io. A pinned ref's root is now fetched directly, checked against the digest, and served from memory when the image's metadata is read. Its type is read from its content, as for a root already in the content store. Tags still start with a HEAD, which is all a later resolve needs when the tag still names local content, and which Docker Hub doesn't count against its pull limit. Signed-off-by: Erik Sipsma <[email protected]>
containerd's fetcher asks only for the media type it's given, and the pinned root is fetched before its type is known. Distribution refuses an OCI manifest or index whose own type isn't in the request's Accept header, wildcard or not, so a digest naming an OCI manifest failed to resolve. The root's download now asks for every manifest and index type, as containerd's resolver does when it resolves a ref. The test registry now refuses a manifest whose type isn't asked for, as Distribution does. Signed-off-by: Erik Sipsma <[email protected]>
…fier limit Signed-off-by: Erik Sipsma <[email protected]>
A call on one collection item receives the whole collection. When every item holds the same object, such as the module it belongs to, the SDK decoded and rebuilt that object once per item, on every call: dagger/go's package collection sent 609 copies of its GoModule, each holding a Go, to each of its 608 item calls. Rebuilding an object evaluates its type's class body, which for those two types is over a hundred members. Calls running at once each held their own decoded copy of the collection. Decode a call's parent and arguments once, keeping the decoded value by its JSON's content while a session that received it is open, and merge equal objects inside it into one. Each call then rebuilds each distinct object once and shares it wherever it occurs, as the module's own value did before it was sent. Only plain decoded data is kept between calls: each call builds its own Dang values against its own engine client. Signed-off-by: Erik Sipsma <[email protected]>
Two received copies of an object holding the same handle are now one object, so they compare equal; before, each copy got its own handle value and Dang compares handles by identity. Pin that answer. Also check that calls sharing one decoded value each build their own Dang values against their own engine client. Say that decoded values are shared by content across sessions too, not only within one. Signed-off-by: Erik Sipsma <[email protected]>
Every artifact a client discovers, evaluates or checks got a standalone dagql server of its own: a fork of the core schema with the module installed again. A listing evaluates each collection receiver this way, so dagger/dagger's listing forked the core schema 814 times, and the first cache hit on each fork re-checked every interface against every object type, queueing on the interfaces' shared mutex. The fork exists so evaluation binds module provenance to results the caller's session owns. It never isolated one artifact from another: a built server is an immutable type registry, and what a call depends on, such as its view or workspace, is on the call's context. Keep the server in the client's schema builder memo, keyed like the builder of the same module set, so a client builds it once per module. A failed build is not kept. Signed-off-by: Erik Sipsma <[email protected]>
Expanding a collection evaluated each deeper receiver by selecting its whole chain again from the module root. A listing of dagger/go's tests re-selected about 3,400 ancestors that the expansion had already evaluated, each a cache hit that takes the cache's write lock. An expansion now keeps the receivers it evaluated, per workspace and view, and starts each deeper evaluation from the nearest one. This also fixes listings under a never-cached ancestor. Each deeper receiver used to run the ancestor again and look up the listed key in the new result. When that run returned different keys, the listing failed with "does not contain key ... in the current subset". Items are now read from the execution whose keys were listed. Signed-off-by: Erik Sipsma <[email protected]>
A session-scoped call, such as Container.from on a tag, gets a new recipe in every session and returns a result every session shares, such as Container.from on the resolved digest. Teaching each session's recipe onto that shared result adds a term to it, so a long-lived engine's shared results gather a term for every session that ever reached them. Two steps of teaching and indexing walked all of a result's terms under the e-graph lock: finding the result's term with a given digest, and recording the request's extra digests on its output eq-classes. On one engine, each unchanged rerun of a 1,233-test suite added about 2,600 terms to one image's result, and planning's calls queued longer on the lock every rerun. Find the result's term through the term-digest index, and record extra digests on the result's output eq-classes, which hold the outputs of all its terms, instead of once per term. Signed-off-by: Erik Sipsma <[email protected]>
When a module object's field holds another module object, the field keeps that object inline, as its fields, and the object becomes its own result: a field call on its owner, which depends on the owner. The owner recorded that result as its own dependency, so each depended on the other, and the owner's persisted state referred to the results inside the inline fields without depending on them. A restarted engine refuses a persisted cache with either, so it discarded the whole cache and started cold. A large module's test runs hit this on every engine restart. The owner now depends on the results its inline fields refer to, and not on the object made from them. A collection base that is the object itself stays out of the inline fields, as it does in the object's own persisted state: decoding sets it again. Signed-off-by: Erik Sipsma <[email protected]>
The owner of an inline object field now depends on the results the inline fields refer to, not on the object made from them. The unit tests now check that: no dependency for a field holding no results, the handle and the collection base a field holds, and no base for an inline collection that is its own base, which decoding sets again. Signed-off-by: Erik Sipsma <[email protected]>
A fresh engine builds the core API's type definitions for each view it serves: once when its first client connects, and again for a module's own engine version. Each build ran every type's dagql selects one after another, about 0.37 s and 0.13 s on a fresh listing of dagger/dagger's tests. Every type's definition is independent of the others, so build them on their own goroutines and keep the schema's order. Signed-off-by: Erik Sipsma <[email protected]>
A client's schema is a fork of the core view's server; the view's type definitions are only needed when a module resolves core types or lists them. Building them with the server put thousands of selects on every fresh engine's first client initialization (about 0.37 s on a fresh listing of dagger/dagger's tests). Build them on first use instead. Signed-off-by: Erik Sipsma <[email protected]>
The core schema's fields and arguments name a few hundred distinct types (String!, [String!]!, Directory!, ...) thousands of times, and building the core type definitions resolved every one of them again, through several selects each, and more for lists and for arguments with an @expectedType. Keep each resolved reference, with an argument's @expectedType, for the rest of the build and reuse it. Signed-off-by: Erik Sipsma <[email protected]>
Building the core type definitions created each function with one select and then set its description, its deprecation and each argument with one more, and added each function to its object with another: about 4,300 selects for the core schema, each a new cache entry. Add __functionExact and __withFunctions, which take the whole function and the whole function list, so each core function and each object's function list is one select. Signed-off-by: Erik Sipsma <[email protected]>
grouville
self-requested a review
November 2, 2026 19:59
grouville
approved these changes
Nov 2, 2026
This was referenced Nov 2, 2026
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 makes evaluating module functions and collections faster, mostly by removing work that grew with a collection's size or with an engine's age. It also fixes two bugs found along the way: a restarted engine could throw away its whole cache, and a listing under a never-cached ancestor could fail.
The measuring workload was a listing of all 4,953 tests of this repository with the dagger/go module (
dagger check --go --check test -l --all). On a fresh engine, the first four commits alone made that listing 2.2 times faster (76.3 → 35.4 s). Each change was measured on its own; see Measured.Convert a collection once per session
Calling a function on one item of a module collection, such as
geton one package of a Go module's packages, passes the whole collection to the module. The engine converted that collection into JSON for the module on every call. For a collection of N items, its N item calls did N² work, and each conversion queued on the dagql cache's lock. This made listing a large repository's tests slow on a fresh engine and after every edit.This helps any module function called many times on the same object, in every SDK.
Evaluate each module and each collection level once
dagqlServerForModule). It built a new one for every artifact, so a listing of this repository built 814 of them. Each new copy also re-checked every interface against every object type on its first cache hit, waiting on a mutex every copy shares. The server is now kept in the client'sSchemaBuilderMemo, keyed the way the memo keys a builder for the same module set, so a client builds it once per module. Discovering a module's artifacts, decoding a persisted module tree, evaluating an artifact and running a check all share it, so every artifact evaluation does less work, not only listings: running checks and generators too, anddagger callon an artifact.Artifact.Evaluate), and that still holds. A built server is an immutable type registry, and it holds none of the dagql result cache. An artifact's view and a check's workspace are applied on each call's context, and module provenance is scoped per call through_implementationScoped.Artifact.Evaluatealready makes, never on returned or persisted trees. Running checks doesn't benefit, since the CLI evaluates each check in its own request.The Dang SDK
It stops asking the engine for IDs it already has. It rebuilds each object the engine passes in from that object's ID, but didn't keep the ID. Returning or passing on such an object then cost one request back into the engine per value, which queued behind other calls' setup in a busy session. It now keeps the ID, but only a handle ID: a recipe ID is still resolved into a handle as before, so module return values pass the same checks.
It rebuilds each object a call receives once. Once item calls no longer queue on the cache, they run at the same time, and each one decoded the whole collection it received into Dang values. Every package entry in a Go module's collection holds the module it belongs to, so each call rebuilt hundreds of identical copies of it and evaluated each copy's body. With many calls overlapping, the engine's peak memory went up several times. Now the SDK decodes each distinct JSON value once, keeping it by content while a session that received it is open, and merges equal objects inside it. Each call still builds its own Dang values against its own engine client, but builds each distinct object once and shares it.
Core type definitions
A fresh engine built type definitions for its whole core API while initializing its first client: one
TypeDefper core type, built from thousands of small cached calls. It built them again for each other API version it served, for example for a module pinned to an older engine version. That is about 0.37 s before the first client's first operation, plus another 0.13 s when such a module loads. Every first session on every fresh engine pays it, CI engines included. Now:String!,[String!]!,Directory!and so on) thousands of times. A resolved reference is now reused for the rest of the build.__functionExactand__withFunctions, follow the existing__functionArgExactpattern. They replace a chain of one call per description, deprecation, argument and function. Like the other hidden fields, they don't appear in introspection or in generated SDKs.The type definitions themselves don't change: same contents, same order.
Smaller fixed costs
dagger.tomldeclares, to key the call. For a module loaded from git or a directory, each read was three cached calls on its tree. One listing of a large module's tests read them about 4,400 times, so about 13,000 cache calls. The tree is an immutable result, so the session now reads them once per tree and module directory. An editeddagger.tomlmakes a new tree, which gets its own read. A local module still reads its host on every call, since the file there can change.Long-lived engines
Address.containergives each call a new identity, andContainer.fromon an image tag one per session; both end atContainer.fromon the resolved digest. The cache records each caller's identity on that result as a new term, so a long-lived engine's shared results gather a term for every call that ever reached them. Two steps under the e-graph lock walked all of a result's terms on every teach and publish of such a call.termForResultByDigestLockednow looks the digest up inegraphTermsByTermDigest, which is kept exact wherever terms are created, repaired, removed, imported and compacted. Extra digests are recorded once on each of the result's output eq-classes, which hold the outputs of all its terms, instead of once per term. The identities themselves still accumulate until the cache prunes them; this change only stops their number from costing time on every call.dagql persistence import failed; wiping and cold-starting, and started empty. This happened whenever the cache held a module object with another module object in one of its fields, for example a Go object with a collection field. The SDK sends such a field inline, as the inner object's fields, and the engine turns that field into its own result, which depends on the owning object. The owner was also recorded as depending on that result, so each depended on the other. And the owner's saved state pointed at the results inside the inline fields without depending on them. The engine checks both when it loads a saved cache, and either one made it reject the whole cache. Now the owner depends on the results its inline fields point to, and not on the result made from the field. A collection that is its own base is left out of the inline fields, as it already is in the object's own saved state; decoding sets it again.Behavior changes
Dang: equal received objects are one object per call. Sharing one rebuilt object where a call used to rebuild each received copy changes three things a module could notice:
==, anduniqandcontainstreat them as one; the same goes for two inline-object arguments of the same type sent with identical JSON;printor an API call, run once per call for equal copies instead of once per received copy;Fields that are sent keep their values and never re-run, and the module that sent the copies usually held one object, so the new answers match what it had.
Listings under a never-cached ancestor now work. Under an ancestor with
+cache="never", every deeper receiver ran the ancestor again and looked up the listed key in the new result. When that run returned different keys, the listing failed withdoes not contain key "…" in the current subset. Items are now read from the execution whose keys were listed. The same applies when a TTL-cached ancestor expires during one expansion. For everything else, results are unchanged: within one request, re-selecting an ancestor returns the same cached result.Measured
All on AWS m8gd.4xlarge machines (16 vCPU, arm64, 64 GB). Unless a line says otherwise, each run was on a freshly started engine, with the arms interleaved. Times are medians and differences are paired means with 95% intervals, so a difference isn't exactly the gap between medians. Every listing run listed exactly the tests
go test -listfinds. Each change was measured on a branch carrying the other pending listing changes, so absolute times are lower than on main.Converting a collection once per session (the first four commits), 3 runs per arm. The base included the other pending listing improvements (#14953, #14934 and dagger/go#89) and the read-lock commit:
Engine CPU on the fresh listing went from 379 to 149 CPU-seconds. The read-lock commit alone saved 5.5 s of an 81 s fresh listing in a separate series; with the other commits applied, its effect on these listings is no longer measurable.
Peak engine memory, and rebuilding each received object once (commits 14 and 15). Letting the item calls run at once raised the fresh listing's peak memory to 5–14 GiB in these runs, and higher in others, varying with how many calls overlapped. Main peaks at about 4 GiB. Rebuilding each received object once brings it below main and also makes the listing faster. "Base" is main with the other pending listing improvements and commits 1 to 6. "main" includes the engine startup fix #14975 and runs an older dagger/go. 3 runs per arm:
With the base image set, the collection's objects hold an engine handle, the case where the merge changes equality. Commits 14 and 15 saved 6.3 s fresh with dagger/go's defaults (6.1 to 6.6 s) and 6.6 s with the base image set (6.5 to 6.6 s), and 0.3 s after an edit in both. The unchanged listing didn't change.
The other listing changes, each measured on its own:
Resolving pinned images without the HEAD saved 0.35 s on the fresh listing, in 4 pairs. One server per module also cut engine CPU on each listing by 2.6 to 3.2 CPU-seconds, and items from the listed receiver made 3,416 fewer ancestor calls per listing and cut engine CPU by about 0.3 CPU-seconds. On a fresh engine, the first
dagger query '{version}'went from 0.79–0.91 s to 0.42–0.44 s with the core type definitions changes, in 6 pairs. Building the definitions took about 0.50 s of the fresh listing before those changes and about 0.27 s after, so the build accounts for about 0.23 s of their 0.42 s. That series ran before a one-line fix, now folded into commit 24, that keeps__functionExactout of telemetry; the fix only removes work.Long-lived engines, on a large Go test suite of 1,233 tests:
dagger check, measured with this change on a branch carrying this PR's other changes and other pending ones: each arm ran a fresh engine, one full run, then 8 unchanged reruns, on two machines. Without the change, reruns 1 to 8 took 22.3 → 60.9 s and 21.8 → 43.8 s, +5.50 and +3.15 s per rerun. With it, 18.7 → 19.6 s and 18.6 → 19.3 s, +0.11 and +0.09 s per rerun. The first unchanged rerun was also faster, 18.7 against 22.3 s and 18.6 against 21.8 s, since the terms pile up within one run too. Full runs on a fresh engine took about the same.docker stop -t 120anddocker startof the same engine, then unchanged runs. Every run passed all 1,233 tests. On main with the engine startup fix engine-dev: retry enabling cgroup controllers when a client connects during startup #14975, none of the cached results survived the restart, and the first run after it took 281.6 s, against 38.6 s for the last rerun before it. With this fix added, all 15,698 cached results came back, and that run took 31.3 s, against 35.0 s.Tests
dagql/cache_session_history_test.gotimes 100 sessions whose calls all reach one shared result, on a new cache and after 10,300 earlier sessions, and fails if the later batch is 3 times slower or more: without the change, 5.2 ms against 251.9 ms; with it, 3.4 ms against 3.4 ms.dagger.tomland another session each get their own read, and a failed read is retried.TestModuleServerSharedPerModulechecks that a client gets the same server for the same module, another module gets its own, servers hold no cache rows, and with no memo every call builds a new server. It fails without its change.TestCollections/TestNestedItemsFromListedReceiverlists items under a never-cached ancestor. It fails with thedoes not contain keyerror without its change.core/integration/engine_persistence_test.goruns a module object holding an inline object and a list of them, restarts the engine, and expects the cached result back. It fails on main with the import error, and runs in thetest-split/test-cache-persistencecheck. The unit tests incore/object_test.gonow check what an inline field's owner depends on, including a collection that is its own base.