INSIDE ZED Upstream ↗ Repository ↗
ENGINE ROOM / 08 · PERFORMANCE

Measured,
not guessed.

Every number on this page came out of a binary linked against the pinned Zed source. The harness lives in harness/ in this repository.

1. What was measured, and how

The harness is a small binary crate whose only dependencies are path links into a checkout of zed-industries/zed pinned at 2664a0aa1eae5dabf8f8273c03f88d53061ca7dc. It does not reimplement anything: it calls Buffer::edit, Buffer::offset_to_point, Buffer::undo, and Rope::chunks on the real types.

./tools/setup-zed.sh
cd harness && cargo build --release && ./target/release/inside-zed-harness

The page reports three independent runs - same host, separately materialised builds, the third from a fresh clone of the published repository - because one run is not evidence of stability. All three raw outputs are committed: harness/results/release-run.txt, release-run-2.txt, and release-run-3.txt. Where they disagree, the disagreement is printed rather than averaged away.

Deterministic results

Structural facts that reproduce bit-for-bit: chunk count, chunk size, document growth, tree shape. No timing involved, so no noise.

Timing results

Medians that moved between runs. Reported per run or as a spread, never as a single authoritative figure.

SCOPE - micro-benchmarks of the text crate in isolation. No GPU, no gpui runtime, no filesystem, no highlighting. They isolate data-structure cost, which is what a source study is trying to characterise.

2. Insert cost versus document size

A single insertion at offset 0 of a freshly built buffer, 25 reps per size, median and minimum per run. The ns/MB column divides median time by document size: if the engine were O(n) in document size, that column would stay flat.

linesbytesmedian µs
run 1
median µs
run 2
median µs
run 3
spread
3 runs
ns per MB
run 1
1 00033 8906.837.626.321.21×211 386
10 000348 89014.7812.9615.301.18×44 412
50 0001 788 89017.7413.7312.901.38×10 400
100 0003 588 89019.1821.7612.691.71×5 603
200 0007 288 89038.3138.4348.081.26×5 512

Content per line: fn line_NNNNNN() { let x = N; } plus newline, 33.89 bytes average (the count grows with the line number's digit width). Sizes are measured from the generated string by doc.len(). Run 3 was executed from a fresh clone of the published repository, not the working copy.

READ THE SPREAD BEFORE THE MEDIAN - the same measurement on the same machine swings up to 1.71× (100 000 lines: 12.69 / 19.18 / 21.76 µs). A third independent run was not needed to confirm the trend; it was needed to show how large the noise is. Publishing one number per size would have implied a precision this harness does not have.

The ns/MB column falls by about 38× while the document grows 215×. That column uses run 1 only; taking each size's slowest of the three runs, the fall is still 34×. The trend is therefore robust to the noise. An editor copying the document per keystroke would show a flat or rising number; this shows the opposite.

WHY THIS SECTION IS THE NOISY ONE - loop A builds a fresh Buffer per rep, so every timed edit lands on a cold tree with the allocator and caches in an arbitrary state. Loop A2, published below, reuses one buffer and measures the same edit warm; it varies by 1.11-1.13× instead of 1.71×. The instability here is a property of the measurement design, not of the engine, and the two loops bracket it from both sides.

A second variant, and why it reports higher numbers

The harness has a second loop over the same sizes. Read it before trusting it, because it does more per rep, not less:

// A: fresh buffer per rep, static "x", construction OUTSIDE the timer
for _ in 0..25 {
    let mut b = buf(&doc);
    let t = Instant::now();
    b.edit([(0..0, "x")]);
    s.push(t.elapsed().as_secs_f64() * 1e6);
}

// A2: one buffer reused, format!() INSIDE the timer, 100 reps
for i in 0..100 {
    let t = Instant::now();
    b.edit([(0..0, format!("{i}"))]);
    s.push(t.elapsed().as_secs_f64() * 1e6);
}
linesA run 1
µs
A2 run 1
µs
A run 2
µs
A2 run 2
µs
A2 run 3
µs
1 0006.8310.4807.6211.82210.500
50 00017.7411.99313.7313.18511.923
200 00038.3113.90638.4314.50712.845

A2 is not "A minus construction". It times a format! allocation plus an edit into a buffer that has already absorbed i earlier insertions, so it measures a different workload. The only column that isolates the data structure is A, where construction sits outside the clock and the inserted text is a static &str.

The A2 row is still worth publishing for one reason: across all three runs it stays between 10.48 and 14.51 µs over a 215× size range, and its own spread is only 1.11-1.13×. Once the per-rep work is fixed and small, document size barely matters - which is the same conclusion A reaches from the other direction, with far less noise.

CORRECTION TO AN EARLIER DRAFT - an earlier version of this page described A2 as isolating the edit by removing Buffer::new from the timer. That was wrong: A already excludes construction. Reading the source is what caught it. Both loops are published above so the claim can be checked rather than taken on trust.

3. Sustained appends

1 000 sequential insertions at the end of a 100 000-line document:

metricrun 1run 2run 3
total for 1 000 edits11.15 ms11.16 ms10.25 ms
median per edit10.57 µs10.61 µs9.96 µs
worst single edit46.59 µs70.05 µs44.93 µs
document growth3 588 890 → 3 588 990 bytes (+1 000, exact, in all runs)

The median is one of the most reproducible numbers on this page: 9.96 / 10.57 / 10.61 µs across three independent builds, a 6.5% total spread. It is also slightly lower than the single-edit figures in section 2 (17.74 µs in A at 50 000 lines, 11.99 µs in A2), which fits an append at the end of the tree being a cheaper path than an insert at offset 0.

ANALYSIS - the worst case is the least stable figure (46.59 / 70.05 / 44.93 µs) and should never be quoted as a bound. A single outlier edit is what a node split plus a cache miss looks like; across 1 000 samples, one such event moves the maximum a lot. The stable median is the load-bearing claim.

Document growth is exactly the bytes written: 1 000 single-byte edits add exactly 1 000 bytes. The rope stores text without padding or per-edit slack, so no capacity slack is hidden between what the document contains and what it costs.

One limit on this section: the harness reports the median and maximum over the run but does not bucket the samples by position in the sequence, so it cannot show whether the last edit is slower than the first. The claim supported here is a stable per-edit median, not a proof that appends never degrade.

4. Offset to point conversion

Converting a byte offset into a row/column Point, 10 000 lookups scattered across a 100 000-line document:

metricrun 1run 2run 3
median81 ns90 ns120 ns
p99552 ns502 ns571 ns
p99 ÷ median6.8×5.6×4.8×
checksum of all results499857184, identical in all three runs

This is the operation a renderer performs per visible line, so it matters more than insert cost for typing feel. At 81-120 ns median, converting a thousand visible lines costs on the order of 80-120 µs before any layout or shaping work.

THE CHECKSUM IS THE REAL RESULT - all 10 000 converted points hash to 499857184 in every run, on three separate builds from two separate checkouts. The timings vary by up to 1.5×; the computed answer does not vary at all. If the tree walk had a bug that returned a wrong point for some offsets, the checksum would move. This is the one place on the page where a claim is exact rather than statistical.

ANALYSIS - the tail is the interesting part: p99 sits at 4.8-6.8× the median across the three runs. That is the cost shape of walking a tree whose depth varies with position, where the deepest leaves pay most. A flat distribution would imply a cached line index, which is not what the source shows.

5. Undo grouping is a compile-time constant

Undo coalescing uses a time window: edits inside the window collapse into one undo step. The value is fixed at construction in History::new (crates/text/src/text.rs):

group_interval: if cfg!(any(test, feature = "test-support")) {
    Duration::ZERO
} else {
    Duration::from_millis(300)
}

The behaviour therefore differs between a production build and any build enabling test-support. Cargo feature unification makes that easy to hit by accident: if a dev-dependency enables test-support, the measurement binary inherits the test value.

TRAP, OBSERVED - the first version of this harness reported group_interval = 0ns and 2 undo steps for 2 rapid edits. The cause was not the engine but test-support leaking in through dev-dependencies. The harness now prints the compiled-in default and then exercises both intervals explicitly, so the mechanism is visible instead of accidentally measured.

group_intervalundo steps for 2 rapid editstext after full undo
300 ms (production)1"hello"
0 ns (test)2"hello"

Both configurations restore the exact original text; only granularity differs. One undo step per typing burst is the intended behaviour.

6. Rope chunk geometry

Walking the chunk iterator of a 100 000-line document. These figures are identical in all three runs because they are structural, not timed:

3 588 890 Bdocument size
28 039chunks
128.0 Baverage chunk
128 Bmax chunk

Average and maximum are both 128 (the harness prints 128.0 after dividing 3 588 890 by 28 039, which is 127.996; the average is truncated on display, and the max is the hard leaf capacity). The exact figure matters: the average sits a rounding error below the capacity, which is what a tree filled by splitting at 128 bytes looks like. No chunk exceeds the cap.

The constant is not arbitrary. In crates/rope/src/chunk.rs the chunk is a fixed-capacity text buffer whose size derives from a bitmap width:

#[cfg(not(all(test, not(rust_analyzer))))]
pub(crate) type Bitmap = u128;
#[cfg(all(test, not(rust_analyzer)))]
pub(crate) type Bitmap = u16;

pub(crate) const MAX_BASE: usize = Bitmap::BITS as usize;
pub(crate) const MIN_BASE: usize = MAX_BASE / 2;

So MAX_BASE is 128 in a normal build and 16 when the rope crate compiles its own unit tests. Each chunk carries four bitmaps over its own bytes - UTF-8 character starts, UTF-16 offsets, newlines, tabs - plus the text itself. 128 bytes is where that per-byte summary stays inside two 64-bit registers while the tree keeps a low fan-out cost.

ANALYSIS - this number explains several others here. A 3.6 MB document needs 28 039 leaves. With a 128-byte leaf and a fan-out around 16, that is a 3-to-4 level tree. Depth grows as log(n), so a 215× larger document costs only a handful of extra levels, not 215× the work. That is the mechanism behind the near-flat ns/byte column in section 2, and why the ratio stayed stable while absolute timings did not.

7. What these numbers do not show

  • Interior edits under load. Offset 0 and appends are covered; random interior positions with concurrent anchors are not.
  • Multi-replica throughput. Delivery, deferred draining, and undo across replicas are exercised by the test suite, not timed here.
  • End-to-end frame cost. Layout, shaping, and GPU draw are outside this harness. An 81 ns offset lookup says nothing about whether a frame fits in 16 ms.
  • Other machines. Absolute latencies are host-specific, and the run-to-run spread documented above is a floor on the uncertainty, not a ceiling.
  • Allocation behaviour. No allocator instrumentation, so split cost is inferred from latency jitter, not counted.
  • The 200k-line row. The median moves a lot across runs (38.31 / 38.43 / 48.08 µs), and within each run the minimum sits 15-24 µs below the median. That single row is the least trustworthy on the page: it is reported in full rather than quietly averaged.
  • 512-byte slices. 1 000 slices of 512 bytes at positions spread across the whole 3.6 MB document: median 1183 / 1282 / 1183 ns, so about 1.2 µs. The scatter stride is (i * 4099) % (len - 512), which covers the document rather than a hot region. Stable across runs because the cost is a tree descent to a position plus copying 512 bytes, and neither depends much on total size.

8. Reproducing

# 1. pin the upstream source (sparse, blob-filtered)
./tools/setup-zed.sh

# 2. build and run the measurements
cd harness && cargo build --release
./target/release/inside-zed-harness

# 3. run the adversarial tests against the same crates
cargo test --release

Step 1 needs network access to GitHub. The toolchain is Rust 1.100.0, the version the pinned upstream commit names in its own rust-toolchain.toml; harness/rust-toolchain.toml pins the same value. Verified from a clean checkout: cargo test --release builds and passes all 33 tests on stable, so no nightly is needed.

REPRODUCIBILITY NOTE - raw output of all three runs is committed under harness/results/ (release-run.txt, -2, -3). If a future run disagrees with a figure, the raw files are the reference and this page is what needs updating. Runs 1 and 2 came from the working copy; run 3 was produced from a fresh clone of the published repository. Expect timing medians to move by up to about 1.7× on the noisiest section; expect structural figures (bytes, chunk counts, checksum) to be exact.