mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
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
This commit is contained in:
@@ -5418,6 +5418,8 @@ impl BackgroundScanner {
|
||||
root_char_bag = snapshot.root_char_bag;
|
||||
}
|
||||
|
||||
let parent_is_private = self.is_path_private(&job.path);
|
||||
let parent_is_hidden = self.settings.is_path_hidden(&job.path);
|
||||
let next_entry_id = self.next_entry_id.clone();
|
||||
let mut ignore_stack = job.ignore_stack.clone();
|
||||
let mut new_ignore = None;
|
||||
@@ -5539,7 +5541,8 @@ impl BackgroundScanner {
|
||||
}
|
||||
}
|
||||
|
||||
if self.settings.is_path_excluded(&child_path) {
|
||||
// `job.path` was checked above, so only the child can match.
|
||||
if self.settings.file_scan_exclusions.is_match(&child_path) {
|
||||
log::debug!("skipping excluded child entry {child_path:?}");
|
||||
|
||||
self.state
|
||||
@@ -5643,18 +5646,16 @@ impl BackgroundScanner {
|
||||
self.settings.is_path_always_included(&child_path, false);
|
||||
}
|
||||
|
||||
if parent_is_private
|
||||
|| (!self.share_private_files
|
||||
&& self.settings.private_files.is_match(&child_entry.path))
|
||||
{
|
||||
let relative_path = job
|
||||
.path
|
||||
.join(RelPath::from_unix_str(child_name.to_str().unwrap()).unwrap());
|
||||
if self.is_path_private(&relative_path) {
|
||||
log::debug!("detected private file: {relative_path:?}");
|
||||
child_entry.is_private = true;
|
||||
}
|
||||
if self.settings.is_path_hidden(&relative_path) {
|
||||
log::debug!("detected hidden file: {relative_path:?}");
|
||||
child_entry.is_hidden = true;
|
||||
}
|
||||
log::debug!("detected private file: {:?}", child_entry.path);
|
||||
child_entry.is_private = true;
|
||||
}
|
||||
if parent_is_hidden || self.settings.hidden_files.is_match(&child_entry.path) {
|
||||
log::debug!("detected hidden file: {:?}", child_entry.path);
|
||||
child_entry.is_hidden = true;
|
||||
}
|
||||
|
||||
new_entries.push(child_entry);
|
||||
|
||||
Reference in New Issue
Block a user