---
title: "Rope & SumTree"
description: "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."
url: "https://swe.quest/articles/rope-sumtree-f2c50a52279e3db4"
canonical: "https://zed.dev/blog/zed-decoded-rope-sumtree"
source: "Zed"
published: "2024-04-23"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 22
tags: ["data-structures","rust","developer-tools","concurrency"]
---

# Rope & SumTree

A post on [Zed](https://swe.quest/sources/zed.md), published 2024-04-23, 22 min read, Deep dive. Original: [https://zed.dev/blog/zed-decoded-rope-sumtree](https://zed.dev/blog/zed-decoded-rope-sumtree)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)
- [Rust](https://swe.quest/tags/rust.md) (Languages)
- [Developer tools](https://swe.quest/tags/developer-tools.md) (Engineering practices)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)

## Prerequisites

- Rust basics ([easy posts on Rust](https://swe.quest/tags/rust.md?difficulty=easy))
- tree data structures ([easy posts on Data structures](https://swe.quest/tags/data-structures.md?difficulty=easy))
- reference counting

## Keywords

Zed, Rope, SumTree, Tree-sitter, Arc, arrayvec, Ropey

## Related posts

- [Rope Optimizations, Part 1](https://swe.quest/articles/rope-optimizations-part-1-32023b24da3832be.md): Zed · 2024-11-18 · Medium · 10 min read · Data structures, Performance engineering, Rust, Algorithms
  Zed'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.
- [Enabling low-latency, syntax-aware editing using Tree-sitter](https://swe.quest/articles/enabling-low-latency-syntax-aware-editing-using-tree-sitter-9ffe8225d976568b.md): Zed · 2023-03-27 · Medium · 10 min read · Developer tools, Compilers, Data structures, Rust
  Zed builds its syntax-aware features on Tree-sitter, a GLR-based incremental parsing framework with error recovery that produces concrete syntax trees.
- [This Week at Zed Industries: #1](https://swe.quest/articles/this-week-at-zed-industries-1-0d07c1f998ae465c.md): Zed · 2023-01-23 · Medium · 4 min read · Developer tools, Performance engineering, Data structures, Rust
  Zed 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.
- [We Have to Start Over: From Atom to Zed](https://swe.quest/articles/we-have-to-start-over-from-atom-to-zed-8db3be76f03d8a79.md): Zed · 2024-02-12 · Easy · 25 min read · Rust, Developer tools, Performance engineering, Data structures
  Zed'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.
- [Zed Has Rainbow Brackets](https://swe.quest/articles/zed-has-rainbow-brackets-56d1fa479c442850.md): Zed · 2025-12-03 · Medium · 6 min read · Developer tools, Rust, Caching, Performance engineering, Testing
  Zed 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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
