← Sat, Nov 28 digest

Swapping Jolt's sorted collections to a B+tree

read article ↗ hn thread ↗

Swapping Jolt's sorted collections from a persistent red-black tree to a B+tree reduced peak memory usage by 40% and improved operation speeds.

read it A detailed engineering postmortem offering concrete benchmarks and architectural insights on replacing tree structures for better cache locality.

summary

The author of the Jolt language replaced its persistent red-black tree sorted collections with a persistent B+tree to improve cache locality and reduce memory overhead. By packing entries into contiguous leaves and inner nodes, tree depth plummeted and lookups became much faster. Although small collection inserts initially regressed, a specialized batch-loading mechanism solved the issue. Benchmarks across millions of entries confirm major reductions in memory and improvements in range queries and reductions.

key points

  1. Red-black tree nodes created 48 bytes of metadata overhead per entry, leading to heavy cache misses on large collections.
  2. The B+tree stores up to 16 entries per leaf contiguously, dropping a 4M-entry tree depth from 22 levels to 5.
  3. A 15% slowdown on small insertions was mitigated by buffering and bulk-loading sorted inputs.
  4. At 4 million entries, the new structure nearly halved peak resident memory from 1.73 GB to 1.04 GB while accelerating walks and range queries.

who should read it

Systems programmers, language implementers, and data structure enthusiasts interested in persistent collections and cache optimization.

discussion positive

consensus

Commenters primarily focused on clearing up ambiguity, noting that the article discusses a Lisp implementation rather than the popular Jolt physics engine.

best comment by speps ↗

FYI it's this Jolt: https://github.com/jolt-lang/jolt

NOT this Jolt: https://github.com/jrouwe/joltphysics

Provides immediate clarification distinguishing Jolt lang from the physics engine many readers initially mistook it for.

Generated by an LLM from the article and thread. Check the sources before relying on it.