INSIDE ZED Upstream ↗ Repository ↗
INVESTIGATION / 03

Positions without renumbering.

An initial investigation of Zed's ordered text locators, the insertion-between operation, and the limits of the available tests.

Source and core operation

The implementation is in crates/text/src/locator.rs. The type is Locator; the key operation is Locator::between(lhs, rhs).

The inspected locator is backed by SmallVec<[u64; 2]>. Its between operation constructs a value ordered between two existing locators, using numeric gaps where possible.

What the tests establish

The inspected tests include a 100,000-step sequential forward append scenario and a 10,000-insertion-at-cursor scenario. They check that locator depth remains shallow for those particular patterns.

VERIFIED - the implementation and tests explicitly exercise locator depth under large sequential and repeated-at-cursor insertion patterns.

ANALYSIS - stable ordering identifiers can remove the need to renumber every later position when inserting between existing positions. The tests indicate common typing patterns are an optimization target.

Open questions

  • What depth results from repeated insertions into the same narrow interval?
  • How does comparison cost scale with depth?
  • Are there normalization or compaction paths?
  • Which invariants apply when operations from different replicas are merged?
  • Which property tests cover ordering, uniqueness, and convergence?

HYPOTHESIS TO TEST - adversarial insertion patterns may produce deeper locators and more expensive comparisons. This is not established by the common-pattern tests alone.

Benchmark plan

A useful benchmark suite should vary workload shape rather than report one aggregate number:

  1. Append-only insertion.
  2. Repeated insertion at a fixed cursor.
  3. Alternating insertion on both sides of a narrow interval.
  4. Randomized insertion among existing positions.
  5. Merge operations generated independently by multiple replicas.

Record elapsed time and resulting locator depth. Keep the workload, input size, hardware, and revision alongside every result.