Repository navigation
Faster loading of a workspace's modules: Go runtimes built while dependencies load, git workspace checkouts reused, filter flags narrowed, dagger/go v0.4.0 - #15063
Merged
Conversation
grouville
self-requested a review
November 4, 2026 18:50
grouville
approved these changes
Nov 4, 2026
Move the workspace's Go module from dagger/go#84's merge commit to the v0.4.0 release. That brings in Go 1.27 (dagger/go#90), the faster workspace scan (dagger/go#91) and the module discovery index and test check cuts (dagger/go#89). dagger.lock records the tag and the sub-modules the release resolves, as written by dagger. Signed-off-by: Erik Sipsma <[email protected]>
A command that selects modules with flags, such as `dagger check --golang --check test -l --all`, loaded every workspace module: to discover its flags, to run, and to name the listing's flags. Only the selected modules can match, so load those. Discovery reads the module names from the workspace config, finds the modules that the command line selects with --module, --by-NAME or the --NAME alias, and registers the flags of their artifacts. Flag names are allocated across modules, and a module's dimension flags start with its name, so it also loads every module whose name extends a selected one at a hyphen, or that a selected one extends. If the command line does not parse with those flags, discovery registers every module's flags, as before, so Cobra's error and usage are unchanged. Help and completion still discover every module. The run already narrowed to the selected modules for module flags alone; a type key such as --check=test no longer widens it, since a type needs no binding and its key resolves among the selected modules' paths. The listing names its rows' flags among the rows' modules and the modules whose names relate to theirs, rather than every module. Signed-off-by: Erik Sipsma <[email protected]>
A narrowed discovery falls back to every module's flags when Cobra would reject the command line, so its error and usage are unchanged. Check the flags' values too, as Cobra parses them, and fall back for --help in any spelling Cobra accepts, such as --help=1. Signed-off-by: Erik Sipsma <[email protected]>
A workspace loaded from a git ref (dagger -W github.com/org/repo@ref) checked the repository out three times: once for the workspace itself, once more for every module its config declares, which loaded as separate git module sources from refs naming the same commit, and once more for those modules' relative dependencies, pinned to the commit. Legacy +defaultPath contexts reused the second checkout. Those module sources also identified their files by the commit: a git module's context is a filtered copy out of the commit's tree, keyed by that tree. So every new commit gave every module new build inputs, even when its files hadn't changed, and a rerun after the branch moved rebuilt every module's runtime. A local checkout rebuilds only the modules whose files changed. Load the modules a git workspace declares at paths in its tree through the workspace instead, with Workspace.moduleSource, as value workspaces and serveModule already do. Their files come from the checkout the workspace already made, their dependencies follow through the same workspace, and the workspace's filtered reads are keyed by the files they select. Such a module's tree, where the modules it serves and the git clients its config declares are found, is the workspace's own. A legacy +defaultPath context loads the same way, as a context-only source of the workspace root. Like a local source without a config, its context directory is an empty dir at its root, and its module variant doesn't change with the commit, as the ref string it replaces didn't. Committed files an ignore rule matches stay in a git module's files, whether it is loaded from a git ref or through a git workspace. One behavior changes: a directory a module reads by +defaultPath from a git workspace no longer contains .git, as the workspace's own tree doesn't. A module that needs git metadata takes a GitRepository or GitRef argument, which keeps working. Local workspaces, and modules from remote refs, load as before. Signed-off-by: Erik Sipsma <[email protected]>
Loading a module loads its dependencies as modules first, then builds its runtime. A Go module configured with dagger-module.toml builds from its committed generated files, so its build reads nothing from its dependencies: only running the built runtime needs their schema. Yet the build waited for every dependency to load, so in a workspace whose Go modules depend on each other the builds ran one after another. Add an optional RuntimePrebuilder interface for a Runtime whose runtime doesn't depend on the module's dependencies for some sources. The Go SDK implements it for sources that skip runtime codegen: it builds the same runtime container Runtime returns, through the same code, and evaluates it so the build runs. asModule runs it alongside the dependency loads. After they load, it reports the build's error if the build already failed; otherwise it goes on, and a definition that isn't cached evaluates the same runtime, joining the build in flight, while a cached one doesn't need it. The prebuild is cancelled when the load returns, and a dependency's failure still fails the module first. A build that fails after that early check fails again, through the definition's own evaluation of the runtime. A source restored from the persisted cache keeps its SDK unloaded and doesn't prebuild. Signed-off-by: Erik Sipsma <[email protected]>
Building a module's runtime while its dependencies load starts every Go module's build together. On a cold Go build cache, builds that run together each compile the packages they share, so a workspace with many Go modules spent more CPU and memory, and finished later, than with the builds spread out. Bound the engine's runtime prebuilds in flight to 4. A prebuild waiting for a slot does no work; if its module's dependencies finish loading first, the module's definition builds the runtime itself, as before prebuilding. On `dagger -W github.com/dagger/dagger@<commit> check -l` on a 16-CPU machine, against main: a fresh engine 45.3 -> 35.0 s, against 41.5 s with no bound, at main's CPU (about 295 CPU-seconds against 290, and 400 with no bound), with a 5.6-6.3 GiB machine memory peak against 8.9 GiB with no bound; after main moved, 1.5 s less saving than with no bound. Signed-off-by: Erik Sipsma <[email protected]>
prepareArtifactCommands grew past the linter's cyclomatic complexity limit when filter flags started narrowing discovery. Move the discovery callback's body into its own function; the behavior is unchanged. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/faster-real-workspace-listing
branch
from
November 4, 2026 20:04
daa0405 to
7b30b83
Compare
A workspace's identity included the digest of its tree. A git tree's digest is its recipe until it's checked out and its content after, and only a successful checkout may equate the two. That makes no difference while loading a git workspace always checks its tree out first, but it ties the workspace's identity to doing so. The tree is determined by the workspace's git ref, which the identity covers. Signed-off-by: Erik Sipsma <[email protected]>
A workspace at a git ref (dagger -W github.com/org/repo@ref) fetched the whole repository and checked it out before loading anything, although loading its modules reads a small part of it: dagger/dagger's load reads about 4% of its files, after fetching 69 MB and writing 17,000. Fetch the commit's trees into a second, blobless mirror of the remote, then fetch and write only the files loading will read: every module config, and the context of each module the workspace's config declares and each local module they depend on, along with every directory of the tree, its symlinks and its attributes. Git writes the files itself, so they are as a checkout writes them. Whether a read can come from this sparse tree is decided read by read, from the commit's whole list of paths, with the same matcher the copy itself uses. A read selecting anything the sparse tree doesn't hold reads the full checkout, which is made as before when something first needs it. So the list of files to fetch only decides how fast a run is: a file it misses makes a read slower, not wrong. Reads are copied and hashed as before, so they have the same content digests either way, and work keyed by them is shared. The sparse tree itself has no content digest: a view into it can't reach what a view into the full tree can. A copy of everything in a directory has the content digest of the directory itself, so the cache can return either for the other, and a view of the directory in the full tree can follow a symlink out of it, which a copy can't. So a read selecting everything in its directory reads the full tree, and any read using the full tree checks it out first, which is what hashes the view before anything can copy it, as always happened while loading checked it out. A filter can select files inside a submodule, which the commit's paths don't list, so a tree with submodules reads everything from its full checkout. The existing mirror, and everything that reads from it, doesn't change. A remote that doesn't support partial fetches sends everything to the blobless mirror, and a failure anywhere leaves the workspace reading its full checkout. Local workspaces, and modules from remote refs, load as before. Signed-off-by: Erik Sipsma <[email protected]>
The helm and installer tests connect with the test's context and close
the client in a cleanup. The Go SDK ends a client's session when the
context it connected with ends, and a test's context ends before its
cleanups run. While dagger/go ran tests inside one outer session, the
client attached to that session and outlived the test's context. Since
dagger/go v0.4.0 each client starts its own session, so the session could
be gone before the cleanup closed the client, and the close failed the
test ("close dagger client: close: exit status 1").
Connect with a context that isn't cancelled with the test's, so each
client lives until its own close.
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
A git workspace's identity no longer includes its tree's digest, so the test that a different rootfs gives another identity no longer holds for one. Its ref determines the tree, and nothing pairs a git source with another tree. Test that as itself, and that a directory-backed workspace's rootfs still counts. A host-backed workspace has no such identity, as before. Signed-off-by: Erik Sipsma <[email protected]>
This was referenced Nov 4, 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.
Five changes that make listing a large workspace's checks faster, most of all
dagger -W github.com/dagger/dagger@main check -l, which loads dagger/dagger's 37 modules, plus a fix to two e2e tests that the dagger/go pin exposed. Each is its own commit or commits.All together, on
dagger -W github.com/dagger/dagger@<commit> check -l(main a45241b against this PR at 5d6263e, each arm's CLI and engine built from its commit, one 16-CPU arm64 machine (m8gd.4xlarge), a priming sequence and 2 interleaved pairs, identical output, 4 Nov 2026):Commits after 5d6263e change tests, and refactor one function without changing its behavior. On the fresh run the machine's memory peak is 5.1–5.2 GiB against 4.1 GiB. The unchanged rerun read +0.24 s over 2 pairs, but that step is mostly GitHub requests and varies by about ±0.3 s from run to run, so this data can't tell a small cost from none (the Go runtime change alone read +0.20 s on 3 pairs and −0.05 s [−0.17, +0.07] on 16).
Before the sparse fetch, this PR's first 6 commits, on their original base against main from the same base (2 interleaved pairs on another machine of the same type), measured fresh 45.6 → 31.8 s (−13.77 s [−15.59, −11.96]), after main moved 18.5 → 7.6 s (−10.89 s [−10.94, −10.84]) and unchanged +0.29 s [+0.12, +0.45], not resolved; on that fresh run the machine's CPU was the same as main's (about 290 CPU-seconds) and its memory peak 5.4–5.9 GiB against 4.4 GiB.
Build a Go module's runtime while its dependencies load (two commits)
Loading a module loads its dependencies as modules first, then builds its runtime. A Go module configured with
dagger-module.tomlbuilds from its committed generated files, so its build reads nothing from its dependencies; only running the built runtime needs their schema. The build waited anyway, so in a workspace whose Go modules depend on each other the builds ran one after another: in dagger/dagger,go→cli-dev→engine-dev→ the client modules →release.The Go SDK now starts that same build, through the same code, while the dependencies load. The build sees exactly what it saw before. A dependency's failure still fails the module first and stops the build. A module whose definition is already cached doesn't wait for the build. One rare case: a build that fails in the short window after the load's early check fails again through the definition's own evaluation, so the error arrives a few seconds later.
On
dagger -W github.com/dagger/dagger@<commit> check -l(16-CPU arm64 machine, against main from the same base, 3 interleaved pairs, identical output):Started all at once, these builds cost CPU and memory on a fresh engine: on a cold Go build cache, builds that run together each compile the packages they share. So the last commit limits the engine to 4 runtime prebuilds at once. A prebuild waiting for a slot does no work, and if its module's dependencies finish loading first, the module's definition builds the runtime itself, as before. Measured on the same command and machine type (3 interleaved pairs against main):
These numbers come from a prototype that held the limit inside the Go SDK, around only the build's evaluation. The commit holds it in the engine, around each module's whole prebuild, so a slot is also held while the module's source is scoped and its build container set up, which on a cold engine can include hashing the module's source. The combined measurement above, of this PR's own commits, is the number for the commit as merged.
After main moved, the limit saves 1.5 s less than no limit (−3.45 s against main, against −4.9 s), because those rebuilds run on a warm cache, where running them together helps. The unchanged rerun is no worse. The engine's own memory doesn't change (0.6 GiB).
About 0.7 s of the 1.3 s unchanged rerun is GitHub requests, so differences under about 0.3 s on that step need many pairs to resolve; 16 pairs resolve about ±0.12 s.
Load a git workspace's modules from its own checkout
dagger -W github.com/org/repo@refchecked the repository out once for the workspace, once more for the modules itsdagger.tomldeclares, and once more for their relative dependencies, and identified each module's files by the commit, so a rerun after the branch moved rebuilt every module. Modules a git workspace declares now load through the workspace, from its checkout, keyed by their files. Ondagger -W github.com/dagger/dagger@<commit> check -lthis saves 5.9 s on a fresh engine (46.0 → 40.6 s) and 7.2 s on a rerun after main moved 89 commits (18.5 → 11.0 s).One behavior changes: a directory a module reads by
+defaultPathfrom a git workspace no longer contains.git. Modules that need git metadata take aGitRepositoryorGitRefargument instead.Fetch and check out only what loading a git workspace reads (two commits)
dagger -W github.com/org/repo@reffetched the whole repository and checked it out before loading anything, though loading reads a small part of it. On dagger/dagger that's 69 MB and 17,000 files, of which about 4% are read.A git workspace now fetches its commit's trees into a second, blobless mirror, then fetches and writes only the module configs and the files of the modules it declares. Each read checks, against the commit's whole list of paths and with the copy's own matcher, whether those files hold everything it selects. A read that needs anything else uses the full checkout, made on first use as before. So does a read of everything in a directory: its copy would share the digest of a view of that directory, which can follow symlinks the copy can't. Reads are copied and hashed as before, so their content digests are the same either way. The existing mirror and everything that reads from it don't change, and neither do local workspaces or modules from remote refs.
On
dagger -W github.com/dagger/dagger@<commit> check -l(16-CPU arm64 machine, against this PR's other commits before their rebase onto current main, 2 interleaved pairs, identical output):Read the fresh saving as about 3 to 4 s. One slow run before the change pulls the two-pair figure up. Loading the workspace itself goes from 5.35 s to 1.54 s, and the listing doesn't change. A recording of the final tree shows no full checkout of dagger/dagger in any of the three steps.
What costs more. A command that reads the whole tree anyway does the new work first:
check -lstill made the full checkout measured about no change fresh and −1.2 to +0.4 s after main moved.dagger.jsonpays about +0.8 s fresh (estimated).+defaultPath="/"still makes the full checkout when it's called, so such a run keeps that cost.One identity change. A git workspace's identity no longer includes its tree's digest. Its git ref determines the tree, and that digest changes once the tree is checked out. Results keyed by such a workspace miss once after upgrading.
Bugs found and fixed while building this, each with a test: a filter reaching inside a submodule lost files; a check re-ran in the next session because its workspace's identity changed; a read of a path missing from the commit forced the full checkout; a view of a directory in the sparse tree could stand in for the full tree's view, and so could a copy of a whole directory, either of which broke a symlink pointing out of it; and on an engine holding the sparse tree only as another engine's cache record, reading it failed and everything used the full checkout.
Module filter flags load only the selected modules
A command that selects modules with a flag, such as
dagger check --golang --check test -l --all, loaded every workspace module: to discover the command's flags, to run, and to name the listing's flags. It now loads the selected modules and their dependencies, plus the modules whose names extend theirs or that theirs extend at a hyphen (such asgo-sdkforgo), since those can share flag names. When the narrowed flags don't accept the command line, and for help and completion, it discovers every module as before.One exception: when another module exposes an artifact whose type has the selected module's name (a dependency's object), the CLI used to withhold the
--NAMEalias; it now accepts--NAMEand lists rows with it, because it no longer loads that other module.--by-NAMEstill selects the module in every case.On dagger/dagger's own workspace, fresh, the median goes from 62.5 to 60.5 s, a mean paired saving of 4.2 s [0.8, 7.7] over six pairs; unchanged, 0.7 s [0.2, 1.2].
Pin the Go runner to dagger/go v0.4.0
dagger/dagger's Go checks run on the dagger/go module pinned in
dagger.toml. That pin was still at dagger/go#84's merge commit, so this repo didn't get anything dagger/go has shipped since. This moves it to the v0.4.0 release, which adds Go 1.27 support (dagger/go#90), test sessions that start only when a test check needs one (dagger/go#83), a faster workspace scan (dagger/go#91) and a module discovery index (dagger/go#89).dagger check -landdagger check -l --alllist exactly the same checks before and after.dagger check -l --allrun again on a warm engine goes from 7.7 to 6.2 s (every one of 6 pairs faster); plaindagger check -ldoesn't change.dagger.lockis as written bydagger.Keep each e2e test's Dagger client open through its cleanup
With dagger/go v0.4.0 (the pin above), Go tests no longer run inside one outer Dagger session: each
dagger.Connectstarts its own session, which the Go SDK ends when the context it connected with ends. The helm and installer e2e tests connected with the test's context, which Go cancels before cleanups run, so the cleanup that closes the client could find its session already gone, and the close failed the test (e2e/helmTestInstallK3Sdid once in CI). They now connect with a context that isn't cancelled with the test's, and the helm test cancels it in its last cleanup.Tests
core/schema), which fails without the change; a load whose definition doesn't need the build returns without it; a dependency's failure and a build's failure each fail the module with their own error; with more modules waiting to prebuild than the limit, exactly 4 prebuild at once (fails without the limit).dagger-module.tomlGo module calling adagger-module.tomlGo dependency, both from committed files (TestRuntimeCodegen/TestCommittedFilesWithDependency).TestWorkspace/TestGitWorkspaceModulesAreContentKeyed, which fails without its change, plus new subtests ofTestWorkspaceLegacyDefaultPathandTestModuleLoading.internal/cmd/daggerand new cases inTestArtifacts/TestCommandModuleLoadScope, whose two new-lcases fail without the change.TestWorkspace/TestGitWorkspaceLoadsWithoutItsWholeTreelists and calls a module on a server that has lost a file outside the modules, and fails without the change.TestGitWorkspaceSparseReadsMatchFullReadscompares content digests with the full tree, at two commits.TestGitWorkspaceModuleReadsOutsideItsFilescovers a+defaultPathread outside the planned files.TestGitWorkspaceFullReadsReachOutsideASparseRead,TestGitWorkspaceSubmoduleReadsMatchFullReadsandTestGitSparseTreeManifestOfAMergedRecordeach failed before their fixes.TestPathTreeSelectsWhatCopySelectscompares the selection walk with a real copy.