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
…
2026-11-17 12:43:21 +00:00
…
2026-11-17 12:43:21 +00:00
2026-11-17 12:43:21 +00:00
2026-09-11 09:13:44 +00:00
…
…
…

Zed

Zed CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

Zed source code is licensed primarily under GPL-3.0-or-later, with Apache-2.0 components where marked.

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.

Sponsorship

Zed is developed by Zed Industries, Inc., a for-profit company.

If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.

S
Description
No description provided
Readme 1.6 GiB
Languages
Rust 95.4%
JSON-with-Comments 2.4%
Python 0.8%
Inno Setup 0.3%
Tree-sitter Query 0.3%
Other 0.4%