You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Directory.filter copies every matched file, so hundreds of filtered views of one tree cost a minute of engine CPU #15028
What happens.Directory.filter(include:, exclude:) builds its result by copying every matched file into a new snapshot. In the engine that goes through Directory.withDirectory and MountRef into layercopy.(*Copier).copyEntry. The result is then hashed from scratch (contenthash.Checksum → scanChecksum), even though every file came from a source whose content hash is already known.
Workload. A Go module checks each package against only the files it reads, so that an edit elsewhere leaves that package's tests cached. The module syncs the workspace once, then derives one view per package with filter(include: [...]). Each view holds the package directory, the non-test .go files of the local packages it imports, go.mod/go.sum, and testdata. A large module has about 500 such views, and they overlap heavily: most of them include the same core packages.
Cost. On an m8id.16xlarge engine (main 117c671 plus #14927, #14953, #15021 and #15025), a push that changes go.mod re-derives every view. The first check starts 62-73 s into the run, and the CLI receives no spans for that window. A 50 s CPU profile of it shows about 16 cores busy:
Share of engine CPU
Where
58%
core.(*Directory).withDirectory → layercopy.(*Copier).copyEntry, mostly in syscalls
18%
contenthash.(*cacheContext).Checksum on the copied results
15%
core.(*Directory).Glob, in patternmatcher.(*PatternMatcher).MatchesUsingParentResults
As a bound, I replaced each package's view with the whole synced tree, which breaks the module's caching and so isn't usable. The first check then started at 31-52 s instead of 62-73 s.
Asks, in order of preference:
Let filter return a view of the source snapshot without copying file contents, for example a bind/overlay of the matched paths, materialized only when an exec mounts it.
When filter does copy, derive the result's content hash from the source's per-file hashes instead of rescanning the copy.
Reflink or hardlink matched files instead of copying them on filesystems that support it.
Related: #15014 and #15021, from the same workload.
Activity