Skip to content

go: one source read per build, huge pages for compiles, smaller module unpacks, and no scan failure on an unused local replace - #97

Closed
sipsma wants to merge 8 commits into
mainfrom
sipsma/gobuild-beta24
Closed

sipsma wants to merge 8 commits into
mainfrom
sipsma/gobuild-beta24

Conversation

@sipsma

@sipsma sipsma commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Three changes that make building Go with this module faster, combined into one PR because they all land with gobuild's move to engine v1.0.0-beta.24, and one fix to the workspace scan. Each keeps its own commits.

What users get. Building dagger's CLI with the go module, on 16-core arm64 machines. Each change was measured on its own on an earlier build, not together and not again on this branch:

Change Measured gain
An edit's build reads the workspace from the client once instead of twice −0.26 to −0.32 s per edit
gobuild's compiles and links ask for transparent huge pages −2.8 s on a cold build, only on a host whose huge pages are set to "always". Elsewhere it changes nothing
Dependency modules unpack without their tests and testdata About half the files and 0.35 GB of the 1.26 GB unpacked, and 0.9 s less engine CPU on a cold build

Regenerating gobuild's client also brings the Go SDK's one-request dispatch: a function call's name, parent and arguments are read in one request instead of one per value. That isn't measured on its own.

gobuild now needs engine v1.0.0-beta.24. It declares engineVersion = "v1.0.0-beta.24" instead of v1.0.0-beta.22, because that's the first release with File.extract's include and exclude patterns.

The first build after upgrading recompiles everything once. Unpacking without tests changes what each module's directory holds, and with it the cache keys of the packages that read it.

An unlisted local replace no longer fails the build. A module whose go.mod carries a local replace of a module it doesn't require, with a target that isn't in the workspace, built with go build but failed dagger/go's workspace scan ("no Go module found for local replace target"). go build reads a replacement only for a module the build needs, so such a replace is usually unused. dagger/dagger's own release, php-client-dev and python-client-dev modules carry one. The scan now leaves an absent target of an unlisted module to go, which reports it at build time if a dependency does need the module. A replace of a module go.mod requires, with an absent target, still fails the scan with the line that declares it.

One source read per build

Each build read the workspace from the client twice, one read after the other: once for the scan and again for the module's source. Both read patterns that match at any depth, so each walked the client's whole tree.

The scan now reads every file a Go build can need whose name alone picks it out, and a module's source reuses that read, which the engine answers from its session cache. The source reads again only the patterns that read doesn't cover, such as embedded files. Those name the directories they are in, so that read skips the rest of the tree.

A ! pattern takes back what the patterns before it selected, which only one read of the whole list in order does. So a source whose patterns hold a ! anywhere is read in one read, as before. The e2e module's scan check covers both !a.go and ./!a.go.

Huge pages for package builds

A package's compile and link set transparentHugePages, since the compiler's heap grows into fresh memory. The setting isn't part of an exec's cache key.

Unpacking without tests and testdata

A build of a dependency never reads its test files or its testdata directories, which the go command ignores, and in some modules they are most of the files. Each module is now extracted through File.extract's exclude patterns, which leave those entries of the zip undecompressed.

What the build plan does read from them is put back: a dependency's tests that go test -c compiles, files a package embeds from testdata, and directories where cgo runs. A module read whole for its C or assembly, whose includes can reach any of its files, is extracted whole, as before. Any other module extracts the same in every build, so its packages' cache keys stay shared across projects.

TestExcludeUnread covers the patterns, and runs in gobuildCheck.

Merging with #95

This and #95 both change gobuild's client. Git merges everything else cleanly, but gobuild/dagger.gen.go conflicts, and whichever merges second regenerates it.

v1.0.0-beta.24 is the first release with File.extract's include and
exclude patterns, which unpacking a module without its tests needs. The
regenerated client also brings withExec's transparentHugePages, and the
Go SDK's one-request dispatch: a function call's name, parent and
arguments are read in one request instead of one per value.

Signed-off-by: Erik Sipsma <[email protected]>
The compiler's heap grows into fresh memory, and on a host set to "always"
huge pages save a cold build most of its page faults (2.8 s of dagger's CLI
first build on a 16-core Graviton4). Elsewhere it changes nothing.

Signed-off-by: Erik Sipsma <[email protected]>
Each build read the workspace from the client twice, one read after the
other: once for the scan, with every Go file and go.mod, and again for
the module's source, with the patterns the scan worked out. Both
patterns match at any depth, so each read walked the client's whole
tree.

The scan now reads every file a Go build can need whose name alone picks
it out (goSource), and a module's source reuses that read, which the
engine answers from its session cache. The source reads again only the
patterns goSource doesn't cover, such as embedded files, and those name
the directories they are in, so that read skips the rest of the tree.

Signed-off-by: Erik Sipsma <[email protected]>
A "!" pattern takes back files the patterns before it selected. Split
across the shared Go source read and the read of the rest, it applied
only to the rest, so a Go file it excluded stayed in the source. A source
whose patterns hold one is read in one read of the whole list, in order,
as before.

Signed-off-by: Erik Sipsma <[email protected]>
Dagger cleans a pattern's path before it looks for a leading "!", so
"./!a.go" excludes a.go, but it doesn't start with one. A source whose
patterns hold a "!" anywhere is now read in one read, as before.

Signed-off-by: Erik Sipsma <[email protected]>
A build of a dependency never reads its test files or its testdata
directories, which the go command ignores, and in some modules they are
most of the files. Each module is now extracted without them, through
File.extract's exclude patterns, which leave those entries of the zip
undecompressed. For dagger's CLI that is about half the files and
0.35 GB of the 1.26 GB unpacked.

What the build plan does read from them is put back: a dependency's
tests that go test -c compiles, and files a package embeds from
testdata. A module none of those come from, nearly every one, extracts
the same in every build, so its packages' cache keys stay shared across
projects.

Signed-off-by: Erik Sipsma <[email protected]>
A package with C or assembly reads its whole module, which its includes
can reach anywhere in, testdata included, without the plan naming the
file. Such a module was still extracted without its tests and testdata,
so an include from testdata failed. It is now extracted whole, exactly
as before the exclusions. A directory read whole, where cgo runs, is put
back whole too.

The exclusions now match only under the module's own directory in the
zip, so a module path with a "testdata" element no longer matches them,
and a file in a directory named like a test file is put back when the
build reads it.

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

go build reads a local replace's target only for a module the build
needs. A replace of a module that go.mod doesn't list, and that nothing
else in the build needs, is unused, and go build never looks for its
target. The scan failed on any local replace whose target wasn't in the
workspace, so a module carrying such a replace built with go build but
not with dagger/go. dagger/dagger's own modules have one: release,
php-client-dev and python-client-dev replace github.com/dagger/dagger
with the repository root, and require nothing from it.

The scan now leaves an absent target of an unlisted module to go: if a
dependency's go.mod does need the module, go reports the missing target
at build time, as it does without dagger/go. A replace of a module go.mod
requires, with an absent target, still fails the scan with the line that
declares it, and a target present in the workspace is still followed.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma sipsma changed the title go: one source read per build, huge pages for compiles and smaller module unpacks go: one source read per build, huge pages for compiles, smaller module unpacks, and no scan failure on an unused local replace Nov 5, 2026
@sipsma

sipsma commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #95, which now carries this PR's commits unchanged alongside the rest of the per-package build.

@sipsma sipsma closed this Nov 5, 2026
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.

1 participant