## Summary While profiling agent sessions that make a lot of `edit_file` operations, I noticed the LSP `textDocument/didChange` handler firing excessively. Looking into this, I found out that the streaming edit pipeline was applying each `CharOperation` from `StreamingDiff` as its own `buffer.edit` transaction, and every transaction emits a `BufferEvent::Edited` event. Each event can trigger several other expensive events depending on whether the buffer is being rendered in an editor or is registered with a language. For example, there are `didChange` LSP events, the editor's on edit work (matching brackets, bracket colorization, code actions, outline), and more. A single `edit_file` could trigger hundreds of these at the higher end in a single synchronous app update, which would block the foreground thread for a bit and cause Zed to drop frames. I fixed this by collecting all of a chunk's `CharOperation`s and applying them in one `buffer.edit` call, so only a single `BufferEvent::Edited` event gets emitted. This is safe because operations are non overlapping by design of streaming diff (the edit cursor only advances). ## Why this wasn't caught earlier The cost only fully appears when a buffer is both registered with a language server and rendered in an editor. Without that, most of the per transaction observers never run, so the existing `edit_file_tool` benchmark (which ran the tool against a bare buffer) didn't surface it. I reworked the benchmark to open the edited buffer in an editor view, register a fake language server with per edit diagnostics, and lay out a frame, so it exercises the same cascade as the real editor. I also added a larger fixture. ## Results Measured with the `release-fast` profile on the reworked benchmark: | Fixture | Initial file | Before | After | Improvement | | --- | --- | --- | --- | --- | | `tiny_function_rewrite` | 1.4 KB | 31.1 ms | 12.1 ms | −61% | | `small_function_rewrite` | 3.0 KB | 42.4 ms | 19.3 ms | −55% | | `medium_many_small_changes` | 4.6 KB | 309.2 ms | 151.5 ms | −51% | | `medium_insertions` | 4.6 KB | 171.8 ms | 126.1 ms | −27% | | `large_multi_edit` | 44 KB | 9,549 ms | 919 ms | −90% | Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the UI/UX checklist - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Improved agent's edit file tool performance
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.