Repository navigation
Speed up package discovery in large workspaces - #72
Merged
Merged
Conversation
sorted() inserted one item at a time with takeWhile and dropWhile: about n² comparisons, each a call into a Dang closure. ownFiles sorts every Go file of a module with it. On the dagger repository, with about 4,000 Go files in its root module, that one sort takes about 10 s of every call. A merge sort whose merge walks both halves once with map takes n log n comparisons and copies each list once per level. Sorting the dagger repository's 4,004 Go files took 20.8 s before and 1.0 s after, run standalone with the engine's dang. The order is the same byte order as Go's sort.Strings. Signed-off-by: Erik Sipsma <[email protected]>
ownFiles left out files in nested modules by comparing every file with every nested module root. In a repository's root module that is files times modules closure calls: about 4,000 times 80 on the dagger repository, on every call. It now looks each directory above a file up in a set of the nested roots. Signed-off-by: Erik Sipsma <[email protected]>
Package discovery listed every module's own Go files twice. Gomod.modules listed them to check that a module holds Go files, sorting a list it only needed the length of. Then Go.packages listed them again for each module through a separate call to gomod, so each module cost one more call into a Dang module: about 80 on the dagger repository. Gomod.modules now lists each module's Go files once, unsorted, checks them there, and returns them as GoMod.goFiles. Go.packages passes them to each GoModule, so finding a module's packages makes no call to gomod. isGoModule still lists the files of the workspace it is given, and a GoMod from at or module has no goFiles. Signed-off-by: Erik Sipsma <[email protected]>
Package discovery needs only which _test.go files declare a test, fuzz or example function, but it read every matching function's path and line through the search API: one result per function, and two field reads on each. On the dagger repository that was thousands of results per call. It now asks the search for files only and reads just their paths. The matched lines are still read where they are used, for a package's test names. Signed-off-by: Erik Sipsma <[email protected]>
Finding a module's main and go:generate packages ran the same marker search three times, once each for package main clauses, ignore build tags and go:generate commands, and read every result's path and line each time. The search is now read once per module and its lines narrowed to each kind in process. Signed-off-by: Erik Sipsma <[email protected]>
grouville
self-requested a review
October 21, 2026 19:03
grouville
approved these changes
Oct 21, 2026
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 21, 2026
…retries The golang workspace module (generate and test checks) still used dagger/go's pull/45 head, which is frozen at its September merge. Pin it to the dagger/go main merge of dagger/go#71, which also contains dagger/go#72: - dagger/go#71 sets GOPROXY to proxy.golang.org|proxy.golang.org|direct in withGoCaches, so a module zip download that the proxy resets mid-stream is retried once against the proxy and, on another proxy failure, attempted directly from the origin. The check can still fail if that fallback fails. - dagger/go#72 speeds up package discovery. The source names a commit rather than main because dagger.lock pins are not applied in Cloud's remote-workspace sessions, so main would float in CI. The dagger/go main entry in dagger.lock is refreshed to the same commit with dagger lock update. dagger/go now organizes checks and generators by package, so their names change: golang/generate-all/stale becomes golang/packages/generate/stale, golang/test-all becomes golang/packages/tests/test, and the golang/generate-all generator becomes golang/packages/generate. Update the release instructions' generate step to the new generator name. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 21, 2026
…retries The golang workspace module (generate and test checks) still used dagger/go's pull/45 head, which is frozen at its September merge. Pin it to the dagger/go main merge of dagger/go#73, which also contains dagger/go#71 and dagger/go#72: - dagger/go#71 sets GOPROXY to proxy.golang.org|proxy.golang.org|direct in withGoCaches, so a module zip download that the proxy resets mid-stream is retried once against the proxy and, on another proxy failure, attempted directly from the origin. The check can still fail if that fallback fails. - dagger/go#72 and dagger/go#73 speed up and fix package discovery. The source names a commit rather than main because dagger.lock pins are not applied in Cloud's remote-workspace sessions, so main would float in CI. The dagger/go main entry in dagger.lock is refreshed to the same commit with dagger lock update. dagger/go now organizes checks and generators by package, so their names change: golang/generate-all/stale becomes golang/packages/generate/stale, golang/test-all becomes golang/packages/tests/test, and the golang/generate-all generator becomes golang/packages/generate. Update the release instructions' generate step to the new generator name. Signed-off-by: Erik Sipsma <[email protected]>
This was referenced Oct 21, 2026
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 21, 2026
…retries The golang workspace module (generate and test checks) still used dagger/go's pull/45 head, which is frozen at its September merge. Pin it to the dagger/go main merge of dagger/go#73, which also contains dagger/go#71 and dagger/go#72: - dagger/go#71 sets GOPROXY to proxy.golang.org|proxy.golang.org|direct in withGoCaches, so a module zip download that the proxy resets mid-stream is retried once against the proxy and, on another proxy failure, attempted directly from the origin. The check can still fail if that fallback fails. - dagger/go#72 and dagger/go#73 speed up and fix package discovery. The source names a commit rather than main because dagger.lock pins are not applied in Cloud's remote-workspace sessions, so main would float in CI. The dagger/go main entry in dagger.lock is refreshed to the same commit with dagger lock update. dagger/go now organizes checks and generators by package, so their names change: golang/generate-all/stale becomes golang/packages/generate/stale, golang/test-all becomes golang/packages/tests/test, and the golang/generate-all generator becomes golang/packages/generate. Update the release instructions' generate step to the new generator name. Signed-off-by: Erik Sipsma <[email protected]>
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 makes package discovery much cheaper on large repositories. Building one binary from the dagger repository takes about 77 s even with nothing to rebuild, and most of that is
Go.packagesdiscovering the packages of every module. Five commits:Merge sort.
sorted()inserted items one at a time withtakeWhileanddropWhile. That is about n² comparisons, each a call into a Dang closure.ownFilessorts every Go file of a module with it. In the dagger repository, whose root module has about 4,000 Go files, the root module's list was sorted three times per call at about 10 s each. All three copies ofsorted()become a merge sort whose merge walks the two halves once withmap. A sort takes n log n comparisons and copies each list once per level, and the result is the same byte order as Go'ssort.Strings. Sorting the dagger repository's 4,004 Go file paths with the engine's Dang took 20.8 s with the old sort and 1.0 s with this one. Those times are for the sort run on its own, including Dang start-up.Nested modules by set lookup.
ownFilesleft out files that belong to nested modules by comparing every file with every nested module root. For a repository's root module that is files times modules closure calls, about 4,000 times 80 on the dagger repository. It now looks up each directory above a file in a set of the nested roots.Each module's files listed once.
Gomod.moduleslisted every module's Go files to check that the module holds any, sorting a list it only needed the length of. ThenGo.packageslisted them again through a separate call into gomod for each module.Gomod.modulesnow lists them once, unsorted, and returns them asGoMod.goFiles, andGo.packagesuses them without calling gomod per module.isGoModulestill lists the files of the workspace it is given, and aGoModfromatormodulehas nogoFiles.Test files by a files-only search. To find packages with tests, discovery only needs which
_test.gofiles declare a test, fuzz or example function. It read every matching function's path and line through the search API instead: one result per function and two field reads on each, thousands per call on the dagger repository. It now asks the search for files only and reads just their paths. Test names still read the matched lines, one package at a time.One marker search read once per module. Finding a module's main and go:generate packages ran the same marker search three times, once each for package main clauses, ignore build tags and go:generate commands, and read every result's path and line each time. It is now read once per module and narrowed to each kind in process.
The module loads and discovers yq's packages on a released engine, with the same keys before and after each commit, and builds yq's binary.
Overall
Before is dagger/go main just before this PR; after is this PR. Both ran on one Dagger Cloud engine, with the beta.19 CLI running inside it. Each module was loaded once first and its Go modules downloaded, untimed. Then, per workspace: a first build with an empty Go build cache, a call with no change, a call after a one-line edit, another call with no change, and three discovery-only calls (
packages | keys). That is one run each, on a shared engine, so differences of a few seconds, or of 10–20 s on the dagger repository, are noise.This ran on the PR's third push, without the last commit (one marker search read once per module). A separate discovery-only run of the final head on the dagger repository is listed below.
Building
cmd/daggerin the dagger repository (80 Go modules, about 4,000 Go files):The first build barely moves here because compiling dominates it. Every call with the old module still spent minutes in discovery, and the edit call took 485 s.
Discovery only on the PR's final head, from a separate run on another Cloud engine: 46 s and 47 s after a first run, all three returning the same 810 package keys as before.
Building yq (one module):
On a repository as small as yq, discovery was already about 2 s and this PR doesn't change it. So the yq first-build and no-change differences are probably the shared engine, not this PR.
The edit floor that remains on the dagger repository is still mostly discovery. A follow-up PR continues there.