Rope & SumTree
Zed represents buffer text with a rope rather than a string, because contiguous strings make mid-file inserts and deletes, line navigation and very large files expensive. Its rope is not a classic binary-tree rope but a SumTree of fixed-capacity inline Chunks of at most 128 characters in release builds. The leaves are reference-counted via Arc, so edits mostly rewire pointers and snapshots are cheap. Concurrent access was the deciding requirement: every edit can hand a snapshot to a background thread for Tree-sitter re-parsing without copying the text, which made the rope win over gap buffers and piece tables.
Related posts
- Rope Optimizations, Part 1
Zed mediumAdeptZed's Rope, a SumTree of 128-byte chunks, sped up offset-to-point translation by storing u128 bitmasks per chunk marking newlines, char boundaries and UTF-16 widths, replacing a per-character loop. With the bitmask, row and column come from masking up to the offset and calling count_ones and leading_zeros, which compile to single CPU instructions and avoid branches. A micro-benchmark shows 57ns versus 1ns, and point_to_offset got up to 70% faster in production. The same technique adds a tabs bitmask, since tab rendering depends on column position and showed up as costly in profiles; wiring it into higher layers comes in a later post.
- Enabling low-latency, syntax-aware editing using Tree-sitter
Zed mediumAdeptZed builds its syntax-aware features on Tree-sitter, a GLR-based incremental parsing framework with error recovery that produces concrete syntax trees. Syntax-aware selection uses the CST directly. Highlighting, symbol outlines, auto-indentation and language injections are each driven by declarative Tree-sitter queries, which compile to state machines matched in a single depth-first walk, so adding a language needs only a grammar and query files. Injected trees, such as JavaScript inside HTML or Rust macro arguments, are kept in a copy-on-write B-tree called a sum tree, which lets edits be re-parsed incrementally on a background thread while the main thread keeps reading the previous snapshot.
- This Week at Zed Industries: #1
Zed mediumAdeptZed grew out of Xray, the experimental editor Nathan Sobo and Antonio worked on at GitHub in 2018, and this weekly update recaps the path from there to a company and a private alpha. It also describes the team's first "quality week" of bug fixing, which they plan to repeat every six weeks. Multibuffer performance in project-wide search got much faster after two fixes. Rope fingerprints, computed with the monoid-homomorphic bromberg_sl2 hash and aggregated through a B-tree, are now stored as HashMatrix values instead of allocated Strings. Excerpts are also built on a background thread and streamed into the multibuffer so the main thread no longer blocks.
- We Have to Start Over: From Atom to Zed
Zed easyNoviceZed's co-founders explain why they abandoned Atom's Electron/JavaScript stack and rebuilt a code editor in Rust: JavaScript's pointer-chasing arrays, uncontrollable GC pauses, and the costly JS/C++ boundary for multithreading made performance work feel like fighting the platform. Rust's ownership model pushed them toward a copy-on-write B-tree (SumTree) rope built on Arc, letting snapshots move to background threads in O(1), and high-level Rust code cut a find-all-matches operation from 1s to 4ms. GPU rendering with custom shaders and signed distance fields came out of necessity after Pathfinder proved too slow. Owning the stack (Tree-sitter, GPUI) lets them change anything, such as adding WASM language extensions, at the cost of building more themselves.
- Zed Has Rainbow Brackets
Zed mediumAdeptZed implements rainbow brackets without language servers or a persistent syntax tree by running each language's tree-sitter brackets.scm queries over independent 50-row chunks and coloring pairs by nesting depth across 7 cycling theme accent colors. Chunks may occasionally be off by one color at boundaries, a tradeoff accepted to avoid maintaining global bracket state. Results are cached on the buffer rather than the ephemeral editor, versioned with clock::Global, invalidated eagerly on edits and re-queried lazily only for visible ranges. Upstream tree-sitter changes that limit query search ranges keep performance acceptable, and a visual test notation annotates each bracket with its color index.