Avoid holding worktree lock for a long time while updating large repos' git status #12266
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.
Fixes #9575
Fixes #4294
Problem
When a large git repository's
.git
folder changes (due to agit commit
,git reset
etc), Zed needs to recompute the git status for every file in that git repository. Part of computing the git status is the unstaged part - the comparison between the content of the file and the version in the git index. In a large git repository likechromium
orlinux
, this is inherently pretty slow.Previously, we performed this git status all at once, and held a lock on our
BackgroundScanner
's state for the entire time. On my laptop, in thelinux
repo, this would often take around 13 seconds.When opening a file, Zed always refreshes the metadata for that file in its in-memory snapshot of worktree. This is normally very fast, but if another task is holding a lock on the
BackgroundScanner
, it blocks.Solution
I've restructured how Zed handles Git statuses, so that when a git repository is updated, we recompute files' git statuses in fixed-sized batches. In between these batches, the
BackgroundScanner
is free to perform other work, so that file operations coming from the main thread will still be responsive.Release Notes: