Files
zed/crates/worktree
Parker Loflin 0d3c40e1b9 worktree: Sort removed entry ids once (#66962)
## Summary

`remove_path_from_snapshot` kept `removed_ids` sorted by inserting each
id at its sorted position. Entries are visited in path order but ids are
assigned in scan order, so most inserts shift part of the `Vec`, and
removing a large subtree is quadratic. This pushes the ids and sorts
once and the resulting `Vec` is the same.

The function runs under the scanner state lock whenever a path is
removed or recursively refreshed. For a directory, that is its whole
loaded subtree.

Times for just the loop:

| Entries | Ids | Before | After |
|---|---|---|---|
| 17,645 | from the scanner | 8.8 ms | 0.19 ms |
| 20,018 | synthetic | 9.1 ms | 0.20 ms |
| 100,010 | synthetic | 195 ms | 1.1 ms |
| 500,005 | synthetic | 5.0 s | 7.0 ms |

The scanner ids were dumped in path order from a scan in a test. The
synthetic ids are assigned breadth-first to a random tree.

## Testing

- The `worktree` integration tests pass
- `./script/clippy -p worktree` passes.

## Self-review

- [x] I have reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Improved worktree scanner performance when large directories are
removed or rescanned
2026-11-14 11:34:40 +00:00
..