Skip to content

go: discover tests from a per-module index, as go test would build them - #89

Merged
sipsma merged 18 commits into
dagger:mainfrom
grouville:perf/module-discovery-index-20261029
Nov 2, 2026
Merged

sipsma merged 18 commits into
dagger:mainfrom
grouville:perf/module-discovery-index-20261029

Conversation

@grouville

@grouville grouville commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

This replaces the earlier draft of this PR. Of the draft's five commits, only Guillaume's discovery index commit stays, with his authorship. It is adapted to #84's final form, where its test callers and one module path changed. The rest of the stack builds on it.

Four are gone:

  • Three were earlier versions of go: run selected tests once per module #84's work, which has since merged: "share module test execution through explicit selections", "use collection list for module inspection", and "report package failures and subtest diagnostics". Main now carries all three behaviors through go: run selected tests once per module #84. The draft's tests/ultrabatch.sh cases (a renamed module, an unselected package that fails to build, a TestMain teardown failure, a failing test and a failing build) are go-dev checks on main.
  • One was a merge commit that brought in that earlier go: run selected tests once per module #84 work.

What it does for users

Listing tests is faster, most of all when nothing changed. Listing all 4,953 Go tests of dagger/dagger (dagger check -l over the Go test collection, wall time, median of 3 interleaved runs per arm, on a 16-CPU arm64 machine with an engine built from dagger/dagger plus the collection changes still in review):

Listing #84 #84 + the discovery index
Fresh engine 97.6 s 78.6 s
Unchanged 23.6 s 4.0 s
After an edit 33.7 s 14.1 s

The rest of the stack takes more off the scan and off each test check. Each commit message gives its own measurement. The largest:

  • The scanner's helper no longer links the Dagger Go SDK: a cold build goes from 465 packages to 95, and the binary from 24 MB to 4.6 MB.
  • The helper is built while the workspace syncs, rather than after it, and without inlining in the standard library (2.85 s to 2.15 s).
  • GoPackage.tests is a stored field, so it no longer runs again in every session: an unchanged listing of dagger/dagger went from 4.34 s to 2.95 s.

Test discovery is also more accurate:

  • Only tests go test would run are listed. Before, every test function in every _test.go file became a check, whatever its build constraints. A file marked //go:build !linux, for example, listed tests that never run on Linux. Discovery now applies Go's build rules for the engine's platform, with the build tags from goflags (and -race, -msan, -asan), the Go version and cgo as the test containers run them. A custom base uses its own go env. An example is listed only when it has an output comment, since go test runs no other.
  • A selected test that never ran fails. Before, a selected test with no result passed whenever its package passed. It now fails, saying go test passed its package without running it.

API changes

  • GoPackage.tests is a field and no longer takes a Workspace argument.
  • Gomod.scan takes optional goflags, goVersion and cgo settings for discovery. With none given it is the same shared scan as before.
  • The scan no longer writes the workspace-wide _discovery_ and _testnames_ files. Each module's discovery is in its own catalogue, listed by _discovery_index_.json.

Relation to #91

This builds on #91's faster workspace scan. Discovery reads each file through #91's single read, and the per-module catalogue and the build-constraint filter sit on top of it.

Testing

dagger/go's own dagger check passes all 80 checks on a fresh v1.0.0-beta.23 engine: main's 78 and two new ones, catalogue-index-check and build-constraints-check.

New tests cover the module layout the index failed to list, discovery under build constraints, and a selected test that never ran. The test report helper's unit tests now run in helper-check. No check ran them before.

@tiborvass
tiborvass force-pushed the codex/pr14802-current-go branch 4 times, most recently from 4a65850 to 68a1c99 Compare November 1, 2026 01:21
@sipsma
sipsma force-pushed the perf/module-discovery-index-20261029 branch from 81f2644 to 0ffb09d Compare November 2, 2026 20:26
@sipsma
sipsma marked this pull request as ready for review November 2, 2026 20:26
@sipsma sipsma changed the title perf(go): index module discovery records go: discover tests from a per-module index, as go test would build them Nov 2, 2026
@sipsma
sipsma changed the base branch from codex/pr14802-current-go to main November 2, 2026 20:27
grouville and others added 18 commits November 2, 2026 20:55
Signed-off-by: Guillaume de Rouville <[email protected]>
GoModule.packages merges the selected package paths, sorted by workspace
path, against the module catalogue's records in one pass. The scanner
sorted those records by module-relative directory instead, which differs
when a directory's name sorts before ".": in a module at m, "-tools"
comes before "." but m comes before m/-tools. The merge then skipped
m/-tools and listing the module failed with "package catalogue does not
contain every selected path".

Sort the directories by workspace path, so the records are in the order
the merge expects.

Signed-off-by: Erik Sipsma <[email protected]>
catalogueIndexCheck called GoPackages.package, the collection's get
function, by its Dang name. The engine exposes that function only as
get(key:), so go-dev failed to load and every one of its checks failed.

The removed assertion asked for a directory outside the collection, which
get refuses. Nothing can reach such a directory any more, so drop it
rather than rewrite it.

Signed-off-by: Erik Sipsma <[email protected]>
With packages read from each module's catalogue, nothing reads the
scanner's global _discovery_ file. GoModule.testNames, which read the
global _testnames_ file, served only GoPackage.tests's fallback for a
package without an entry, and every key of a GoPackages collection now
has one: GoModule.packages builds an entry for each selected path, subset
narrows only the keys, and get refuses a key outside them.

Stop writing both files, remove their readers, and make a package's
selected tests required. The discovery line format is now documented on
the module catalogue that carries it.

Signed-off-by: Erik Sipsma <[email protected]>
helperCheck ran only the source scanner's tests, so go-test-report's
never ran in any check. Run both helpers' tests.

Signed-off-by: Erik Sipsma <[email protected]>
A selected test with no result in the report passed whenever its package
passed, on the grounds that a build constraint may have excluded it. Such
a test never ran, so its check showed a pass with nothing behind it.

Report it as not run instead, saying go test passed its package without
it.

Signed-off-by: Erik Sipsma <[email protected]>
Discovery listed every test function in every _test.go file, whatever
its build constraints, so a test in a file go test leaves out on the
engine's platform became a check. A file marked //go:build !linux, say,
listed tests that never run on Linux. Examples without an output
comment were listed too, though go test compiles them and never runs
them.

The scanner now lists a test file's tests only when go/build would build
the file for go test: for the platform the scan runs on, which is the
engine's and so the test container's, with the build tags of the GOFLAGS
go test runs with, the release tags of its Go toolchain, and cgo as it
is configured. The go module passes those settings to the scan: its
goflags and version settings, with no cgo, since the default containers
have no C compiler; or, for a custom base, what the base's own go env
reports. With nothing to pass, the scan stays the one every module and
tool shares. GOFLAGS is split and its -tags parsed as cmd/go does it, and
-race, -msan and -asan add their tags as cmd/go adds them.

An example counts only when go/doc finds the output comment go test
needs to run it.

This changes the scanner's earlier intent, which mirrored the old ripgrep
search and listed tests from files marked //go:build never.

Signed-off-by: Erik Sipsma <[email protected]>
The README still said build constraints were not evaluated and that a
test excluded by one was listed anyway. Describe what discovery lists
now, and that a selected test that did not run fails. The scan's own
documentation now says that test settings passed for discovery make a
scan of their own.

Signed-off-by: Erik Sipsma <[email protected]>
GoPackage.tests took a Workspace argument it no longer read. A host
workspace gets a new identity in every session, so the function ran
again in every session for every package. As a stored field it is read
from the object without calling the module.

Signed-off-by: Erik Sipsma <[email protected]>
The go-includes helper kept a second mode that read the workspace through
the Dagger API, and so linked dagger.io/dagger, otel-go and their gRPC and
OpenTelemetry tree. Nothing has called that mode since the scan moved to a
local pass over a snapshot of the workspace, but every fresh engine still
compiled it: the helper's go build is most of discovery's time there.

Remove that mode and make the local scan the helper's only one, so it
links only the standard library and golang.org/x/mod. A cold build of the
helper goes from 465 packages to 95, and the binary from 24 MB to 4.6 MB.

Signed-off-by: Erik Sipsma <[email protected]>
The scanner was one chain: the image, the helper's go build, then the
workspace mounted into it. Dang has to resolve the workspace directory's
ID before it can send that chain, and resolving it is when the engine
syncs the files from the host. Only then did the engine resolve the
image, and only the read of the scan's output ran the pull and the build.
So on a fresh engine the sync, the resolve, the pull and the build ran
one after another, though the helper doesn't depend on the workspace.

Ask for the built helper and the synced workspace in one {{ }}, whose
fields run at once, and mount the one into the other.

Signed-off-by: Erik Sipsma <[email protected]>
A scan allocates quickly and exits within a fraction of a second, but
at the default GOGC of 100 the collector runs many times during it. In
the scanner's image on dagger/dagger's tree, GOGC=400 takes a scan from
109 ms to 93 ms, with peak memory going from 70 MB to 115 MB. Higher
settings save no more: with the collector off, the scan takes 103 ms
and 315 MB.

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

The scanner builds its helper from source on every fresh engine, and
most of that build is compiling Go's standard library. Without inlining
there (-gcflags=std=-l), the build takes 2.15 s instead of 2.85 s in the
scanner's image.

On its own the change makes each scan about 25 ms slower: the garbage
collector and the strings functions lose their inlined helpers. Running
the scan with less garbage collection, the commit before this one, makes
up for it: 109 ms with both, against 109 ms before either.

Signed-off-by: Erik Sipsma <[email protected]>
Comment-only. The scan takes about 0.1 s, not under it, the quarter is of
the whole build, and the 15% is against a helper built with inlining.

Signed-off-by: Erik Sipsma <[email protected]>
runTests gathered, deduplicated and sorted every selected test name in
the module, with the merge sort in Dang, but only a narrowed run uses
them, for its -run pattern. Every check of the module evaluates
runTests, so a full run of a module with about 900 tests did that sort
once per test. A CPU profile of an unchanged rerun of such a suite
put 56 of the engine's 218 CPU-seconds under Dang's map builtin, most of
it likely this sort's merge step.

Signed-off-by: Erik Sipsma <[email protected]>
GoTest.test worked out its package's import path from the module's
discovery lines, and runTests, which it calls, did the same again: two
lookups per check, each three scanner queries plus the calls around
them, about 45 engine calls. The selections runTests returns already
hold each package's import path next to its module-relative directory,
so the check now finds its selection by directory and takes the import
path from it.

A package missing from the selection is now named by its workspace path
rather than its import path, as the check's other failures already are.

Signed-off-by: Erik Sipsma <[email protected]>
testEnv mounted the workspace's dagger-module.toml and dagger.json files
with its own Workspace.directory call. The engine keys that call per
client, and every check is a client of its own, so a full run of
1,233 tests read the host checkout for them 1,233 times.
gomod.daggerConfigs makes the same read as a module call, which the
engine shares between checks in a session, as it already shares the
module's source and testdata.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the perf/module-discovery-index-20261029 branch from 0ffb09d to c7a589d Compare November 2, 2026 21:09
@sipsma
sipsma merged commit e327bee into dagger:main Nov 2, 2026
82 checks passed
sipsma added a commit to dagger/dagger that referenced this pull request 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]>
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.

3 participants