## Summary `BackgroundScanner` workers hold the `state` lock for about 85% of an initial scan, so work under the lock sets the scan time. `scan_dir` now does less of it: - It reserves one block of entry IDs per directory after `read_dir`. Per-child IDs interleaved with other workers' IDs, so each `entries_by_id` edit inserted in about 12 places instead of one. - It skips `reuse_entry_id` when there are no removed entries and the directory has no loaded children, as during an initial scan. These lookups accounted for 58% of all path comparisons on a Linux checkout. - It sorts children by name before it takes the lock, so `SumTree::edit` gets them nearly in order. - It checks `is_path_excluded` before it takes the first lock. 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 (21 per variant, 7 for Firefox): | Tree | Entries | Before | After | |---|---|---|---| | Linux checkout | 120,916 | 354.9 ms | 274.0 ms | | Firefox checkout | 532,906 | 2.27 s | 1.85 s | | Zed checkout | 5,339 | 37.9 ms | 35.8 ms | After was faster in every Linux and Firefox run, and in 19 of 21 Zed runs. CPU time is unchanged. Both versions found the same entries in every run. GitHub-hosted runners (4 vCPUs, 3 on macOS), shallow clones, same harness, median of alternating runs (21 per variant, 11 for Firefox; 101 and 41 on macOS): | Runner | Tree | Before | After | After faster | |---|---|---|---|---| | `ubuntu-latest` | Linux | 874.9 ms | 818.0 ms | 20/21 | | `ubuntu-latest` | Firefox | 5.52 s | 5.23 s | 11/11 | | `ubuntu-latest` | Zed | 75.3 ms | 74.9 ms | 13/21 | | `macos-latest` | Linux | 1.13 s | 1.10 s | 61/101 | | `macos-latest` | Firefox | 9.32 s | 9.24 s | 24/41 | | `macos-latest` | Zed | 85.0 ms | 80.3 ms | 58/101 | | `windows-latest` | Linux | 7.93 s | 7.83 s | 15/21 | | `windows-latest` | Firefox | 36.22 s | 35.81 s | 11/11 | | `windows-latest` | Zed | 629.7 ms | 629.0 ms | 12/21 | The scanner starts one worker per CPU, so the runners have less lock contention to remove. Pinned to 4 cores, the local Linux scan improves by 11% instead of 23%. macOS runner times vary by up to 2× between runs. ## Testing - `cargo test -p worktree --features test-support` and `cargo test -p project --features test-support --test integration` pass. - Without the `removed_entries` check, four of these tests fail, including `test_rescan_and_remote_updates`, which checks that renamed files keep their IDs. Without the loaded-children check, 22 fail. - `./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: - Improved the time to scan large projects when they are opened
Zed
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:
- Web (tracking discussion)
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 specifiederror for a crate you've created? If so, addpublish = falseunder[package]in your crate's Cargo.toml. - Is the error
failed to satisfy license requirementsfor 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 theacceptedarray inscript/licenses/zed-licenses.toml. - Is
cargo-aboutunable to find the license for a dependency? If so, add a clarification field at the end ofscript/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.