Git - optimize worktree ignored-path computation#303955
Merged
lszomoru merged 1 commit intomicrosoft:mainfrom Mar 23, 2026
Merged
Git - optimize worktree ignored-path computation#303955lszomoru merged 1 commit intomicrosoft:mainfrom
lszomoru merged 1 commit intomicrosoft:mainfrom
Conversation
…tree include paths
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the Git extension’s worktree include-file handling by avoiding redundant parent-directory traversal when building the set of git-ignored include paths in Repository._getWorktreeIncludePaths().
Changes:
- Fixes the loop early-exit condition to check
gitIgnoredPaths(which contains accumulated directory paths) instead ofgitIgnoredFiles(which contains only file paths). - Reduces repeated
path.dirnametraversal for many ignored files sharing the same parent directories, while keeping the resulting path set unchanged.
lszomoru
approved these changes
Mar 23, 2026
joaomoreno
approved these changes
Mar 23, 2026
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.
Fix inefficient parent directory traversal in
_getWorktreeIncludePaths().Problem
The loop that builds parent directory paths for git-ignored files uses
gitIgnoredFiles.has(dir)as the early-exit condition. SincegitIgnoredFilesonly contains file paths (not directory paths), this check is always false for directories, so every file traverses all the way up to the repo root -- redundantly re-adding the same intermediate directories.Example with 100 ignored files under
node_modules/a/b/:b/ -> a/ -> node_modules/ -> root, totaling 400 iterationsb/in the Set and stop immediately, totaling ~103 iterationsFix
Change
gitIgnoredFiles.has(dir)togitIgnoredPaths.has(dir). ThegitIgnoredPathsSet accumulates directories as they are added, so subsequent files sharing the same parent chain skip already-processed directories.The final Set contents are identical --
Set.addon an existing element is a no-op.