# More git status optimizations \(\#2779\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/a01d9734775d6bff567db023d0b99f9e9da6de0a)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: a01d9734775d6bff567db023d0b99f9e9da6de0a

Requested commit: a01d9734775d6bff567db023d0b99f9e9da6de0a

Commit: a01d9734775d6bff567db023d0b99f9e9da6de0a

Tree: 153edb9c95569ed0db7ee0e834743a561f5671c2

Author: Max Brunsfeld

Committer: GitHub

## Message

```
More git status optimizations (#2779)

Follow-up to https://github.com/zed-industries/zed/pull/2777
Refs https://github.com/zed-industries/community/issues/1770

In this PR, I reworked the way that git statuses are retrieved. In a
huge repository like `WebKit`, the really slow part of computing a list
of git statuses is the *unstaged* portion of the diff. For the *staged*
diff, `git` can avoid comparing the contents of unchanged directories,
because the index contains hashes of every tree. But for the *unstaged*
portion, Git needs to compare every file in the worktree against the
index. In the common case, when there are no changes, it's enough to
check the `mtime` of every file (because the index stores the mtimes of
files when they are added). But this still requires an `lstat` call to
retrieve each file's metadata.

I realized that this is redundant work, because the worktree is
*already* calling `lstat` on every file, and caching their metadata. So
in this PR, I've changed the `Repository` API so that there are separate
methods for retrieving a file's *staged* and *unstaged* statuses. The
*staged* statuses are retrieved in one giant batch, like before, to
reduce our git calls (which also have an inherent cost). But the
`unstaged` statuses are retrieved one-by-one, after we load files'
mtimes. Often, all that's required is an index lookup, and an mtime
comparison.

With this optimization, it once again becomes pretty responsive to open
`WebKit` or `chromium` in Zed.

Release Notes:

- Optimized the loading of project file when working in very large git
repositories
```

## Parents

- [76036594792d085ed86c9add0ea85291cecdf554](https://git.cafe/gitcafe/zed/commit/76036594792d085ed86c9add0ea85291cecdf554?format=markdown)

- [8fff0b0ff8ade2b43f2608824a3cc7b3878afae3](https://git.cafe/gitcafe/zed/commit/8fff0b0ff8ade2b43f2608824a3cc7b3878afae3?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/a01d9734775d6bff567db023d0b99f9e9da6de0a?format=markdown)
