Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid holding worktree lock for a long time while updating large repos' git status #12266

Merged
merged 4 commits into from
May 25, 2024

Conversation

maxbrunsfeld
Copy link
Collaborator

Fixes #9575
Fixes #4294

Problem

When a large git repository's .git folder changes (due to a git 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 like chromium or linux, 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 the linux 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:

  • Fixed a bug that caused long delays in opening files right after performing a commit in very large git repositories.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label May 25, 2024
@maxbrunsfeld maxbrunsfeld merged commit f7a8696 into main May 25, 2024
8 checks passed
@maxbrunsfeld maxbrunsfeld deleted the large-git-repo-performance branch May 25, 2024 00:41
maxbrunsfeld added a commit that referenced this pull request May 29, 2024
…12444)

I realized that somehow, the `git` executable is able to compute `git
status` much more quickly than libgit2, so I've switched our git status
logic to use `git`. Follow-up to
#12266.

Release Notes:

- Improved the performance of git status updated when working in large
git repositories.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
1 participant