Repository navigation
Conversation
A host directory read walks the whole client tree in the CLI and matches every path against every include pattern. Patterns such as "**/*.go" or "sdk/go/**/*.go" each compiled to a regexp, and dagger/go's source read of dagger's own tree passes about 110 of them. Matching them was most of the CLI's CPU in each read, about 0.45 s per build, and the walk runs on one goroutine, so it was wall time too. A pattern made of literal text, one "*" or "**/*", then literal text within one path element now matches with prefix and suffix comparisons. It matches exactly the paths its regexp did. A "^" keeps a pattern on its regexp, where it is an anchor. The fsutil filter, which both the CLI's walk and the engine's mirror walk use, now uses this package rather than the upstream one it was forked from. Patterns compile when they are created rather than on first match, since the CLI matches against them from several goroutines, so a match can no longer fail. Building dagger's CLI with dagger/go, an unchanged rebuild goes from 1.98 s to 1.56 s, and an edit is 0.27 to 0.46 s faster. Signed-off-by: Erik Sipsma <[email protected]>
Without it, go generate in sdk/go cannot find the package and fails resolving the module graph. Signed-off-by: Erik Sipsma <[email protected]>
Contributor
Author
|
Folded into #15007, which carries these two commits unchanged. |
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.
Every
host.directoryread walks the client's tree in the CLI and checks each path against each include pattern. Patterns such as**/*.goorsdk/go/**/*.goeach compiled to a regular expression, so a read with many patterns spent most of its time in Go's regexp backtracker, on the single goroutine that walks the tree.This shows up in any module that reads the workspace with many include patterns. For example, building dagger's own CLI with the
dagger.io/gomodule reads the workspace twice per build, the second time with about 110 patterns. In a CPU profile of an unchanged rebuild, the CLI spent 0.60 s walking, 0.45 s of it in regexp matching. An execution trace showed the walk wasn't waiting on the engine, so all of that was wall time.What changes
util/patternmatcher: a pattern made of literal text, one*or**/*, then literal text within one path element (*.go,dir/*.go,dir/**/*.go) is matched with prefix and suffix comparisons instead of a regexp. It matches exactly the paths its regexp matched. A test checks this against the regexps, including the edge cases: zero directories under**/, separators, newlines, and regexp metacharacters in the literal parts. A pattern containing^keeps its regexp, where^is an anchor.internal/fsutil's filter, used by both the CLI's walk and the engine's mirror walk, now usesutil/patternmatcher(dagger's fork) instead ofgithub.com/moby/patternmatcher.go-client-devuploadsutil/patternmatcher, whichinternal/fsutilnow imports, sodagger generate's Go client generator still finds it.Measured
Building dagger's CLI with
dagger.io/go(go | packages | get cmd/dagger | binary) on a 16-CPU Graviton4 machine, 5 runs per side, alternating:Every unchanged rebuild with this change was faster than every one without it. The two workspace reads of an unchanged rebuild went from 0.68 s to 0.26 s.