## Summary A change to any buffer made the multibuffer's next sync read every buffer and diff, and adding a buffer counted as a change. With N buffers, each change cost O(N). Inserting excerpts syncs first, so building a multibuffer one path at a time took O(N²) time on the main thread. Project search, project diagnostics, multi-file git diffs, and find references all build their multibuffers this way. The multibuffer keeps a set of the buffers that changed or were added since the last sync, and a sync reads only those buffers and their diffs. `Buffer::record_changes` takes this set in place of a changed flag, and each buffer adds its ID when it changes. The snapshot stores each buffer's dirty, deleted-file, and conflict flags and counts how many buffers have each one, so `is_dirty`, `has_deleted_file`, and `has_conflict` don't scan every buffer. This also fixes three cases where the multibuffer stayed out of date until another buffer changed: - The `Buffer` methods `did_reload`, `set_capability`, `set_conflict`, and `set_agent_selections` changed dirty, conflict, or selection state without marking the buffer as changed. - Removing a buffer didn't update `is_dirty`, `has_deleted_file`, or `has_conflict`. - `MultiBuffer::clone` dropped changes that the original hadn't synced yet. Benchmark: a test searches an in-memory project of N files, with two matches in each, in a `ProjectSearchView`. Both versions call `MultiBuffer::sync_from_buffer_changes` N + 1 times, and sync time is the total of those calls. Release build, single-threaded GPUI test executor, multibuffer and worktree invariant checks off, Ryzen 7 9800X3D, median of five alternating runs of `main` and this branch: | Files | Sync before | Sync after | Sync speedup | Search before | Search after | Search speedup | |---|---|---|---|---|---|---| | 1,000 | 49.4 ms | 2.4 ms | 21× | 4.21 s | 4.13 s | 1.02× | | 2,000 | 216.3 ms | 5.2 ms | 42× | 10.59 s | 10.24 s | 1.03× | | 4,000 | 928.5 ms | 9.8 ms | 95× | 30.17 s | 28.83 s | 1.05× | ## Testing - `test_dirty_state_across_buffers` checks `MultiBuffer::is_dirty` across three buffers through edits, saves, a reload, a capability change, and an excerpt removal. It fails on `main` at the reload. - `test_deleted_file_and_conflict_state_across_buffers` marks two buffers deleted, then conflicted, without editing them, and clears or removes them one at a time. Each flag stays set until its last buffer is cleared or removed. It fails on `main` at the first conflict check. - `test_clone_with_pending_changes` clones a multibuffer before it syncs a buffer edit and checks that both copies show the edit. It fails on `main`, where the clone misses the edit. - After each mutation, the randomized multibuffer tests check that each buffer's snapshot matches the buffer's version and flags, and that the counts agree with the flags. - `cargo test -p multi_buffer`, `cargo test -p editor -p search -p language`, and `./script/clippy -p multi_buffer -p language` pass, as do the randomized multibuffer tests with `ITERATIONS=300`. ## 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 performance of multibuffers with many files, such as large project search results
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.