Repository navigation
contenthash: don't walk the parent directory to checksum a file - #14555
Merged
Merged
Conversation
grouville
self-requested a review
October 8, 2026 05:37
grouville
approved these changes
Oct 8, 2026
Checksumming a path that is not yet in a ref's cache context walked the
path's parent directory recursively. For a file at the root of a
container filesystem, such as Container.file("/stamp") on an exec
output, that is a walk of the whole filesystem: about 36,000 entries
for a Go toolchain image, once per exec snapshot.
When the resolved path is not a directory, record only that path. The
record and its digest are the same ones the walk produced. Directory
records are still only added by walks, so a directory in the tree still
has all of its contents, and later directory or sibling checksums scan
as before.
Signed-off-by: Erik Sipsma <[email protected]>
…lesystem Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
contenthash-file-no-walk
branch
from
October 8, 2026 08:08
3140b4d to
5299a26
Compare
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.
Problem
Reading a file from an evaluated directory (
Directory.file, and soContainer.file) gives the file a content digest. To checksum a path that is not yet in a snapshot's content-hash cache, the cache walked the path's parent directory recursively. For a file at the root of a container filesystem, such asContainer.file("/stamp")on an exec output, that is a walk of the whole filesystem: about 36,000 entries for a Go toolchain image, once per exec snapshot.On a workload that runs one exec per Go package (yq, 263 packages) and reads
/stampfrom each, this was the largest own-time item in the engine's wall-clock profile. Probes inside the resolver showed 145 s of its 167 s (summed across concurrent calls) in that walk. Hashing the file bytes took 0.27 s.Fix
When the resolved path exists and is not a directory, record only that path in the cache instead of walking its parent. The record, and so the digest, is the same one the walk produced. Directories, missing paths and errors keep the existing walk. Directory records are still only added by walks, so later directory, sibling and pattern checksums behave as before.
Before / after
Cold
gcexp replay --concurrency 16of yq on a dev engine (wcprof), main vs. this change:Directory.fileown time, summedDirectory.filep50Directory.filemaxEach side ran once on a shared host. Unrelated profile classes varied by up to 2x between the two runs, so the whole-replay delta is approximate; the drop for
Directory.fileis far larger than that noise.Tests
TestChecksumFileDoesNotWalkParentinengine/contenthashfails before the change (/stamp: scanned 108 entries) and passes after. It also checks that file, symlink, directory and root digests match those of a full walk, and that missing paths still error. It runs intest-split/test-packages.