Repository navigation
perf: match .dockerignore patterns once per path when listing docker dependencies - #10220
Open
John98Zakaria wants to merge 2 commits into
Open
John98Zakaria wants to merge 2 commits into
John98Zakaria wants to merge 2 commits into
Conversation
…dependencies Listing the dependencies of a docker artifact matched every pattern against every path and all of its parent directories, and did so again for every COPY source that contains the path. The dockerignore predicate now remembers which patterns match a directory, so a path below it is only matched itself, and remembers its results. WalkWorkspace no longer walks a directory again that it listed for an earlier COPY source. An ignored directory is now skipped unless a negated pattern can match below it. Before, a negated pattern with wildcards, such as !**/*.md, did not prevent skipping, so files that Docker sends to the daemon were missing from the dependencies. Amp-Thread-ID: https://ampcode.com/threads/T-01a1db16-b0fa-71dc-b4b6-090d7f504eb4
…ults WalkWorkspace now skips a subdirectory that an earlier COPY source already listed, in either order of the sources. That makes the predicate's per-file result cache unnecessary, so it is removed, along with the cached skip decision and the mutex: every caller creates its own predicate and walks sequentially. Amp-Thread-ID: https://ampcode.com/threads/T-01a1db16-b0fa-71dc-b4b6-090d7f504eb4
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
John98Zakaria
marked this pull request as ready for review
November 14, 2026 18:14
John98Zakaria
marked this pull request as draft
November 14, 2026 23:25
John98Zakaria
force-pushed
the
dockerignore-faster-dependency-listing
branch
from
November 14, 2026 23:27
033227a to
ec663e4
Compare
John98Zakaria
marked this pull request as ready for review
November 15, 2026 00:41
This branch has not been deployed
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.
Description
Listing the dependencies of a docker artifact (
docker.WalkWorkspace, used fortagPolicy: inputDigest, the build cache and file watching) is slow for Dockerfiles with manyCOPYinstructions and a.dockerignorewith many patterns. A CPU profile shows the time inNewDockerIgnorePredicate→patternmatcher.MatchesOrParentMatches→ regexp matching:MatchesOrParentMatchesmatches every pattern against the path and against each of its parent directories, for every file that is not ignored.COPYsource that contains the file, for exampleCOPY svc/srcfollowed byCOPY svc.This PR changes two things:
MatchesOrParentMatches: the last pattern that matches a path or one of its parents decides.WalkWorkspaceskips a directory that it already listed for an earlierCOPYsource.Measured on a synthetic workspace with 38,793 files (30,500 of them ignored), 151
COPYsources and 45 patterns, 5 runs each on 4 vCPUs:BenchmarkWalkWorkspace(included)skaffold build --dry-run -qwithinputDigestThe
inputDigesttag of the synthetic artifact is the same before and after.Tests, in
pkg/skaffold/docker/dockerignore_test.go:patternmatcher.MatchesOrParentMatches, and checks that no skipped directory contains a path that is not ignored.COPYsources, in both orders. This test also passes without the change.I ran the tests of
pkg/skaffold/docker/...,lint,graph,syncandbuild/customlocally, not the full suite or the linters.User facing changes
One bug fix changes the reported dependencies. An ignored directory was skipped unless a negated pattern had the directory as a literal prefix, so a negated pattern with wildcards did not prevent skipping.
Before: with
**/node_modulesand!**/*.md,app/node_modules/pkg/README.mdis missing from the dependencies, although Docker sends it to the daemon.After: the file is a dependency. An ignored directory is skipped unless a negated pattern can match below it. For repositories with such patterns,
inputDigesttags change once.Follow-up Work
patternmatcher.MatchesOrParentMatchesandMatchesUsingParentResults, which BuildKit uses, appear to disagree for some lists with negated patterns. This PR keeps the behaviour ofMatchesOrParentMatches.GetDependenciesByDockerCopyFromTo(skaffold lint) creates a predicate for eachCOPYinstruction, so it gains from the cheaper matching but not from skipping listed directories.