Skip to content

Git - optimize worktree ignored-path computation#303955

Merged
lszomoru merged 1 commit intomicrosoft:mainfrom
xingsy97:wt/git-fix-ignored-paths-loop
Mar 23, 2026
Merged

Git - optimize worktree ignored-path computation#303955
lszomoru merged 1 commit intomicrosoft:mainfrom
xingsy97:wt/git-fix-ignored-paths-loop

Conversation

@xingsy97
Copy link
Member

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. Since gitIgnoredFiles only 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/:

  • Before: each file walks b/ -> a/ -> node_modules/ -> root, totaling 400 iterations
  • After: first file walks the full chain, remaining 99 files hit b/ in the Set and stop immediately, totaling ~103 iterations

Fix

Change gitIgnoredFiles.has(dir) to gitIgnoredPaths.has(dir). The gitIgnoredPaths Set 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.add on an existing element is a no-op.

Copilot AI review requested due to automatic review settings March 23, 2026 04:38
@vs-code-engineering
Copy link
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/src/repository.ts

@vs-code-engineering vs-code-engineering bot added this to the 1.113.0 milestone Mar 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of gitIgnoredFiles (which contains only file paths).
  • Reduces repeated path.dirname traversal for many ignored files sharing the same parent directories, while keeping the resulting path set unchanged.

@xingsy97 xingsy97 changed the title Git - fix redundant parent directory traversal in worktree include paths Git - optimize worktree ignored-path computation Mar 23, 2026
@lszomoru lszomoru enabled auto-merge (squash) March 23, 2026 07:43
@lszomoru lszomoru merged commit 2edf08f into microsoft:main Mar 23, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants