Files
zed/crates/worktree
Parker Loflin 4122f44f6f worktree: Check ancestor paths once per scanned directory (#67022)
## Summary

`scan_dir` checks each child against `file_scan_exclusions`,
`private_files` and `hidden_files`. Each check matched the child and
every one of its ancestors, so the ancestors of the directory being
scanned were matched again for every child. They are now matched once
per `scan_dir` call, and the loop matches only the child's own path. For
exclusions the directory's part is known to be false, because `scan_dir`
returns early for an excluded directory. The loop also no longer
rebuilds the child's path for the private and hidden checks.

This runs for every entry on initial scans and rescans.

The checks alone, over the 96k entries of the Linux snapshot in the
project panel benchmark with default settings, take 165 ms before and 55
ms after (3.0x). Both versions produced the same excluded, private and
hidden flags for every entry, with `share_private_files` on and off.

Whole initial scan with `Worktree::local` and `RealFs` in a headless
app, one scan per process, warm file cache, Ryzen 7 9800X3D (16
threads), median of alternating runs (9 per variant, 5 for Firefox):

| Tree | Entries | CPU before | CPU after | Wall before | Wall after |
|---|---|---|---|---|---|
| Linux snapshot as empty files, tmpfs | 96,305 | 1,737 ms | 1,603 ms |
494.7 ms | 488.8 ms |
| Linux checkout | 120,916 | 2,210 ms | 2,033 ms | 604.5 ms | 595.2 ms |
| Firefox checkout | 532,488 | 12.60 s | 10.92 s | 4.31 s | 4.23 s |
| Zed checkout | 5,337 | 141 ms | 134 ms | 43.2 ms | 42.9 ms |

CPU time drops 8 to 13% on the large trees. Wall time drops 1 to 2%: the
scan is limited by `BackgroundScanner::state`, which workers hold for
about 90% of the scan, mostly to insert each directory's entries, so
less work outside that lock doesn't shorten it.

## Testing

- `cargo test -p worktree` passes, including
`test_file_scan_exclusions`, `test_hidden_files` and
`test_private_single_file_worktree`.
- `./script/clippy -p worktree` passes.

## Self-review

- [x] I've 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:

- N/A
2026-11-17 19:53:23 +00:00
..