Expanse: Modernized Judy Arrays

For the past few months, I have been deep in the weeds of sparse data structures. What started as a focused effort to cut worker memory in PHP with Judy arrays quickly turned into a major rabbit hole: vendorizing, fixing, and hardening libJudy itself after finding latent compiler bugs in the 20-year-old upstream C code.

Diving back into Doug Baskins’s original 20,000-line C codebase reminded me of the exact visceral reaction I had when I first read it twenty years ago: my eyes were bleeding.

It is a monument of early-2000s low-level wizardry—dense macros, custom chunk allocators, manual SWAR (SIMD Within A Register) bit-twiddling, and cryptic pointer tagging. The core algorithmic ideas behind Judy arrays were brilliant, but the implementation was so notoriously complex that almost the entire software engineering field eventually walked away from it.

Over the last two decades, when engineers needed high-performance ordered collections or bitsets, they reached for B-Trees, Adaptive Radix Trees (ART), or Roaring Bitmaps instead. Not because those structures were fundamentally more cache-efficient than Judy, but because nobody wanted to maintain, debug, or port 20,000 lines of arcane C macro soup to new CPU microarchitectures. The clearest proof: ART, the field’s go-to in-memory index since 2013, is itself an adaptive radix trie — its Node4/16/48/256 layouts revisit the same idea as Judy’s linear, bitmap, and uncompressed branches. The industry never refuted Judy’s design; it rebuilt a simpler subset of it and moved on.

With today’s AI agentic coding harnesses and formal verification tools, that cognitive barrier is largely gone. I found myself asking a question that had lingered in the back of my mind for years:

What would Judy arrays look like if designed from scratch for modern hardware?

The result of that exploration is Expanse: a clean-room, hardware-vectorized digital trie engine in pure Rust, with every unsafe block carrying a documented safety argument and tested under Miri and AddressSanitizer in CI, along with libexpanse—a drop-in C ABI replacement for libjudy.


Why “Expanse”?

In tree search literature, most data structures partition their keys by population (the number and distribution of keys currently stored). A B-Tree or Red-Black tree dynamically rebalances, splits, and merges nodes as keys are inserted, keeping the tree balanced relative to its population.

Judy arrays do something fundamentally different: they partition by expanse.

“Expanse, population, and density are not commonly used terms in tree search literature, so let’s define them here: Expanse is a range of possible keys […] A digital tree divides up the population (index set) uniformly by expanse (dividing and redividing the initial expanse evenly), while other methods, such as b-trees, divide up the population by the distribution of the population itself.”
— Doug Baskins & Alan Silverstein, Judy IV Shop Manual (2002)

Population Partitioning (B-Trees) vs Expanse Partitioning (Digital Tries)Both columns look up the same key, 715,064,296, which is 0x2A9F03E8 in hex. The B-tree walks three pages, binary-searching stored pivot keys at each hop. The trie decodes the key's own bytes: 2A picks a fixed slot in the top 256-slot range, 9F picks a slot in the 0x2A000000 subexpanse, byte 1 (03) is folded into the edge as a narrow-pointer skip, and E8 lands on the match in the terminal leaf — no stored key is ever compared.◆ Population Partitioning (B-Trees)Boundaries follow the stored key distributionRoot Page (binary search stored keys):10M250M700M ≤ K < 1.8B1.8BInternal Page (search subrange bracket):700M700M ≤ K < 725M725M850MLeaf Page (find exact key):715,010,040715,064,296 ✔715,190,800● Full keys stored explicitly inside every node● Traversal requires binary search loops per hop● Insertions trigger cascading page splits & rebalances● Tree layout is dependent on insertion order◆ Expanse Partitioning (Judy / Expanse)Fixed byte-range boundaries • same key: 0x2A9F03E8 = 715,064,296Byte 3: 0x00000000 … 0xFFFFFFFF (256 slots):0x2Adirect positional offset (no search)Byte 2: 0x2A000000 … 0x2AFFFFFF (256 slots):0x9Fbyte 1 (0x03) skipped— narrow pointerByte 0: 0x2A9F0300 … 0x2A9F03FF (Terminal Leaf):0xE8 → Match ✔● No full keys in index nodes — the path infers the prefix● Direct positional indexing (SWAR digit find, popcount rank)● Writes affect only local subexpanse (zero tree rebalance)● Invariant layout for ANY key insertion order
Both columns look up the same key — 715,064,296 is 0x2A9F03E8. The B-tree binary-searches stored pivot keys at every hop; the trie reads the key's own bytes as positions, and byte 1 never even costs a hop — its single-child level is folded into the edge as a narrow-pointer skip.

The B-tree binary-searches stored pivot keys at every hop; the Expanse trie reads the key’s own bytes as positions, and byte 1 never even costs a hop — its single-child level is folded into the edge as a narrow-pointer skip.

An expanse-partitioned 256-ary digital tree decodes keys byte-by-byte, from the most significant to the least significant byte. Because the branching boundaries are fixed a priori by numerical byte ranges:

  1. Tree structure is invariant to insertion order: Inserting keys in ascending, descending, or random order produces the same tree. There are zero tree rotations, zero cascading page splits, and zero rebalancing passes.
  2. Keys are inferred by position: Full 64-bit integer keys do not need to be duplicated and stored inside index nodes. The path through the tree is the key prefix; only the trailing uncompressed bytes are stored at the leaves.
  3. Predictable mutation latency: Writes affect only the local subexpanse, providing deterministic latency without write-stall spikes.

Here is that same decode again, level by level — each byte magnifies the slot it picked into the next level’s whole range:

Decoding the key 0x2A9F03E8 by re-dividing a fixed expanseFour bars, one per key byte. The top bar is the full range 0x00000000 to 0xFFFFFFFF; byte 3, value 2A, selects one of its 256 slots. That slot is magnified into the second bar, the range 0x2A000000 to 0x2AFFFFFF, where byte 2, value 9F, selects the next slot — and so on through 0x2A9F0000 to 0x2A9FFFFF and 0x2A9F0300 to 0x2A9F03FF, until byte 0, value E8, lands on the key itself.KEY 0x2A9F03E8 — EACH LEVEL MAGNIFIES THE CHOSEN SUBEXPANSE64-bit key • leading zero bytes (7–4) skipped via narrow-pointer compression0x00000000 … 0xFFFFFFFFByte 3 · 0x2ATop branch (256 slots)chosen slot expands into the next level's entire 256-slot range0x2A000000 … 0x2AFFFFFFByte 2 · 0x9FMid branch0x2A9F0000 … 0x2A9FFFFFByte 1 · 0x03Sub branch0x2A9F0300 … 0x2A9F03FFByte 0 · 0xE8Terminal leafkey match: 0x2A9F03E8 ✔
Each bar is the slot selected above it, magnified into the next level's whole range — the trie divides and re-divides a fixed key range instead of comparing against stored keys. The marker position is computed from the byte value alone, which is why the tree is identical for any insertion order and writes stay local: the properties population-partitioned trees pay rotations and page splits to keep.

The reason naive 256-ary tries are rarely used in practice is memory bloat: allocating 256 pointers (2 KB on 64-bit) at every branch node wastes 99% of memory when only a few keys are present.

Judy solved this with adaptive polymorphic compression: branches dynamically morph between packed linear arrays, 2-tier bitmap subexpanses, and uncompressed tables based on local density. Small populations are stored immediately inside the 16-byte parent pointer itself — up to 15 key-remainder bytes, so 15 keys at one byte each, or 2 at seven — bypassing heap allocations entirely.


The 2002 vs. 2026 Hardware Mismatch

When Doug Baskins designed Judy IV at HP around 2000–2002, the hardware assumptions were radically different from the CPUs powering our servers today:

Architectural DimensionJudy IV (2002)Expanse (2026)
Target CPU GeometryHP PA-RISC / Itanium class enterprise servers.Commodity 64-bit: x86-64, ARM64, RISC-V servers (64-byte L1/L2 lines).
Cache Line GeometrySized for 128-byte lines; straddles 64-byte boundaries.Every node sized to exact 64-byte and 128-byte multiples — zero straddles.
Bit Scanning & RankSWAR bit-twiddling and unrolled lookup tables.Native hardware bit ops: ARM cnt+addv, x86-64 POPCNT (x86-64-v2+), TZCNT (x86-64-v3+).
Search EngineScalar unrolled comparison loops over byte arrays.SWAR broadcasts & runtime-dispatched SIMD (SSE2 → AVX2/BMI2, ARM NEON).
Memory ManagementCustom chunk allocator (2, 4, 6, 8-word chunks).Slab page pools, intrusive freelists, and zero-allocation immediates.
ConcurrencySingle-threaded; external coarse-grained locks.Optimistic lock coupling with epoch-based reclamation (v0.6.0: single writer mutex, optimistic readers; concurrent writers since v0.7.0).
Memory Safety~20,000 lines of macro-heavy C with segfault risks.Pure Rust #![no_std] core, with every unsafe block carrying a documented safety argument and tested under Miri and AddressSanitizer in CI.

Judy IV was tuned for the wide cache lines of its era’s HP enterprise hardware: its own design documents size nodes around 16-word cache line fills — 128 bytes on a 64-bit machine. Sean Barrett saw the same mismatch from the 32-bit side in 2003: 16 words there are 64 bytes, and he noted that Judy was designed for 64-byte cache lines while running mostly on machines with 32-byte lines ( A Performance Comparison of Judy to Hash Tables).

On modern 64-bit server microarchitectures (x86-64, ARM64, and 64-bit RISC-V), the standard L1 and L2 cache line size is 64 bytes. When data structures engineered around 128-byte boundaries are traversed without 64-byte alignment awareness, child pointers and node metadata frequently straddle two adjacent 64-byte cache lines. Every straddle forces a second cache line fetch, doubling the memory cost of that hop.

Furthermore, calculating popcounts and ranks in bitmap nodes in 2002 required multi-step SWAR math. Today ARM64 counts bits with a NEON cnt+addv pair, and x86-64 does it in one POPCNT at x86-64-v2 (TZCNT needs BMI1, so x86-64-v3) — with a portable SWAR fallback retained for base targets.

BranchL3: a complete branch node in one 64-byte cache lineA 64-byte cache line drawn byte 0 to byte 63. The first 16 bytes are the branch header: version counter, child count, level, presence filter, and a sorted 8-byte digit word. The remaining 48 bytes are three full 16-byte edges. Finding the digit 8C is one SWAR pass over the digit word, selecting edge 2 in the same cache line.BRANCHL3 — A COMPLETE BRANCH NODE IN ONE 64-BYTE CACHE LINE▸ Find digit 0x8C: one SWAR pass over the sorted digit wordmatch index 2 → edge 2 (zero cache miss)ver (4B)nlvpres0A428C·····edge 016 B pointeredge 116 B pointeredge 2 ✔16 B target edgebyte 0byte 63 (64 Bytes Total)16 B header · sorted digit word3 full 16-byte packed child edges16 B header + 3 × 16 B edges =64 B exactly— the whole branch resolves in a single cache line fill.Larger nodes are exactly two lines (BranchL7: 7 edges • BranchB: 256-bit bitmap) — a node never straddles memory lines.
Judy IV sized its nodes for the 128-byte cache lines of 2002 hardware, so on modern 64-byte lines they straddle — and every straddle is a second memory fetch. Expanse sizes every node to exactly one or two lines: the one-line BranchL3 above resolves a digit with one SWAR pass over the header's digit word and lands on a full 16-byte edge without leaving the line.

Inside Expanse: Architecture of a Modernized Digital Trie

Expanse is a clean-room build: published descriptions and black-box differential testing against a compiled stock binary, never the LGPL source. Transliterating Judy IV into Rust was never the interesting version of this project anyway. In 2002 C, Judy relied heavily on upper-bit pointer stealing, unaligned word reads, and bespoke chunk allocators that assumed an isolated, single-threaded world.

To build a data structure that survives modern server workloads, I had to rethink the engine around three modern hardware primitives: strict 64-byte cache lines, virtual address sanity (supporting 57-bit PML5 without corrupting pointers), and optimistic multi-core read scaling.

You can inspect the live tree structure, node transitions, and memory layouts interactively in the Expanse Architecture & Benchmark Visualizer.

The four node layouts Expanse morphs betweenAs local key density rises, a branch changes shape: up to 15 key bytes stay inlined inside the 16-byte edge with no heap allocation; a linear branch packs 3 edges into one 64-byte cache line (7 edges into two) found by a SWAR scan of its sorted digit word; denser subexpanses become a 128-byte bitmap branch ranked with popcount; only a dense subexpanse grows into a 4 KiB uncompressed slab of 256 edges indexed directly. Because byte boundaries are fixed, each change is local and never rebalances the tree.◀ sparsedense ▶KEY DENSITY IN THE SUBEXPANSEkey 0key 1…16-byte edge (inlined)ImmediateUp to 15 key bytesInlined in the parent edge✔ zero heap alloc0A1F428CB3C0sorted 8-byte digit wordLinear branch3 edges • 64 B (1 line)7 edges • 128 B (2 lines)⚡ SWAR digit scan256-bit bitmap (8 subexpanses)Bitmap branch256-bit bitmap • 128 BPacked child pointer arrays⌘ popcount rank256-edge slab arrayUncompressed256 edges • 4 KiB slabDirect array indexing➤ direct O(1) index
A branch changes shape with the density of the keys under it — small subexpanses stay inline in the 16-byte edge, and only a dense one grows into a 4 KiB slab. Because the byte boundaries are fixed, each transition is local: the tree never rotates or rebalances.

1. 64-Byte Cache Line Node Geometry & Single-Line SWAR

Expanse re-engineers the digital trie geometry specifically around exact 64-byte and 128-byte cache-line multiples (with 32-byte alignment support for embedded profiles):

2. Optimistic Concurrency Control (OCC) with Epoch-Based Reclamation

In multi-threaded server environments, traditional tree structures hit a hard concurrency wall. Coarse-grained mutexes bottleneck all cores, while read-write locks (RwLock) trigger massive cache-invalidation storms as readers contend for the lock word.

Expanse solves this with per-node versioned Optimistic Concurrency Control (SyncExpanseMap and SyncExpanseSet). Readers traverse the trie without taking a lock, validating generation version tags on descent. On 100%-read workloads, reader throughput scales across cores while keeping the ordered iteration a sharded hash map cannot offer: SyncExpanseMap serves 322.8 M reads/s at 16 threads (95% CI [322.1, 323.5]; a second run measured 321.6 [321.2, 322.1]), measured on a later build than v0.6.0 (commit f9853201), per the committed run 1 and run 2 results.

The honest limit, stated plainly: as released in v0.6.0, this is a single-writer design. Under a 50/50 read/write mix, writes serialize on one mutex, and the threads spend their time handing it off. Readers are optimistic and take no lock on the common path, but the protocol is blocking: a reader spins while a writer holds a node’s version open, and falls back to the writer mutex after 64 failed validations. This is optimistic lock coupling ( Leis et al., The ART of Practical Synchronization, DaMoN 2016) with epoch-based reclamation. DashMap and SkipMap win that regime outright.

Update: multi-writer support has since shipped. From v0.7.0, writers on disjoint subtrees run in parallel under per-node version locks, first on SyncExpanseSet and SyncExpanseMap; current releases use those locks for inserts and removals on every 64-bit wrapper, and keep the writer mutex for fallbacks, root-state changes and whole-tree operations ( architecture §4.2).

3. Pure Rust Core with a Drop-In libJudy C ABI

The core engine is #![no_std] Rust, verified against memory leaks, data races, and undefined behavior using Miri and Loom.

At the same time, libexpanse exports the legacy C ABI:

On 64-bit builds, these legacy Judy1/JudyL/JudySL/JudyHS symbols are a drop-in for libJudy, checked by black-box differential testing against stock libJudy: a C, C++, or PHP application linking against libJudy can replace -lJudy with -lexpanse without code changes. 32-bit builds do not export the legacy symbols. CI also runs the php-judy regression suite against libexpanse, with zero failures.


Performance & Memory Benchmarks

If there is one thing I learned while hardening libjudy, it is that benchmarking low-level data structures is full of traps. It is shockingly easy to measure test-harness teardown or memory-allocator recycling instead of algorithmic speed, or to compare an inlined static Rust library against a dynamically linked C library.

To ensure apples-to-apples comparisons, every benchmark in Expanse is evaluated against explicit baseline implementations across identical key distributions (uniform random, sequential runs, clustered 256-key bursts, and Zipfian distributions).

Full benchmark datasets and Callgrind profiles are documented on the Expanse Benchmarks page.

1. Memory Density (Bytes per Key)

I measured memory footprint with deterministic allocator accounting (NodeAlloc)—the one benchmark that is machine-independent and reproduces byte-for-byte:

Key Distribution (ExpanseSet, 1M keys)Bytes / keyNote
Sequential integers0.07full-expanse + bitmap-leaf compression ( results)
Uniform random 64-bit7.92not part of the dense/clustered design target; density-dependent, see the sawtooth post ( results)
Sparse (i << 40)16.31one 16-byte edge per isolated key—the structural floor ( results)

On genuinely sparse keys the trie’s floor is a 16-byte edge per isolated key, and other structures have regimes where they win.

2. Throughput Against Named Baselines

Point lookup: Expanse vs Rust stdlib collectionsOrdering of Expanse against BTreeMap, HashMap, BTreeSet and HashSet on point-lookup hits at 10k and 1M keys over four key distributions, from two committed runs.Point lookup (hit) · Expanse vs Rust stdlib collectionsWhich container is faster in each cell, shown only where both committed runs agree. Second line: Expanse time ÷ competitor time,as the range spanned by both runs’ BCa 95% intervals (below 1 = Expanse faster). The two runs differ on many magnitudes, so no single ratio is quoted.Expanse faster in both runsCompetitor faster in both runsParity (order not claimed)ExpanseMap vs BTreeMap / HashMap10,000 keysvs BTreeMapvs HashMap1,000,000 keysvs BTreeMapvs HashMapsequentialExpanse faster0.156–0.157×Expanse faster0.807–0.813×Expanse faster0.107–0.112×Parity*0.936–0.986×randomExpanse faster0.222–0.224×HashMap faster1.142–1.164×Expanse faster0.367–0.374×HashMap faster3.315–3.375×clusteredExpanse faster0.158–0.159×Expanse faster0.826–0.836×Expanse faster0.118–0.119×HashMap faster1.037–1.050×sparseExpanse faster0.155–0.156×Expanse faster0.812–0.815×Expanse faster0.076–0.078×Expanse faster0.697–0.709×ExpanseSet vs BTreeSet / HashSet10,000 keysvs BTreeSetvs HashSet1,000,000 keysvs BTreeSetvs HashSetsequentialExpanse faster0.110–0.111×Expanse faster0.553–0.558×Expanse faster0.058–0.059×Expanse faster0.484–0.488×randomExpanse faster0.198–0.202×HashSet faster1.041–1.060×Expanse faster0.349–0.354×HashSet faster3.139–3.180×clusteredExpanse faster0.114–0.117×Expanse faster0.594–0.610×Expanse faster0.078–0.079×Expanse faster0.668–0.682×sparseExpanse faster0.128–0.130×Expanse faster0.653–0.659×Expanse faster0.071–0.072×Expanse faster0.628–0.635×* Both committed runs put ExpanseMap slightly ahead here (0.936–0.986×), too narrowly to claim an order.Random keys lose to the hash containers at both sizes, and the gap grows with the population.Measured: i9-12900F reference host, CPUs 0-15, benches/compare.rs at orieg/expanse 82eb56af; runs 42686709479 and 42691800559, committed in 6ec29a65 asresults/baseline_compare.json and results/baseline_compare_run2.json. Ratio intervals: two-sample BCa (scripts/bca_bootstrap.py, seed 42) recomputed per run.

The lookup chart comes from two runs of the same build (commit 82eb56af), committed as run 1 and run 2 with their tables in BENCHMARKING.md. The two runs agree on which container is faster in every cell, but their intervals do not overlap on many of the magnitudes, so the chart shows the ordering and the range both runs span rather than one ratio. Against BTreeMap and BTreeSet, Expanse is faster in every cell. Against the hash containers it depends on the keys: uniform-random keys lose at both sizes, and clustered keys lose to HashMap at a million keys. Sequential keys at a million entries against HashMap are shown as parity: both committed runs put Expanse slightly ahead (0.936–0.986×), too narrowly to claim an order.

OCC concurrency: 100% read at 16 threadsMULTITHREADED OCC CONCURRENCY · 100% READRead throughput at 16 threads · M ops/sec · higher is better · bounded 2xPOP keyspace (#375)Expanse OCC armBaselineBars are 16-thread throughput on a zero-based linear axis; the badge is that arm's own 1→16-thread scaling.Two runs of one commit: bars are run 1, labels and badges read run 1 / run 2. Compare arms only within the key type under each name.SyncExpanseSet522.6 / 529.3 M ops/s6.84x / 6.93xu64 keys, 1M presentSyncExpanseMap322.8 / 321.6 M ops/s9.12x / 9.15xu64 keys, 1M presentSyncExpanseBlobMap266.6 / 267.4 M ops/s9.23x / 9.24xu64 -> 128-byte payload, 200k presentSkipMap<u64, (Vec<u8>, u32)>33.7 / 33.7 M ops/s11.15x / 11.16xu64 -> 128-byte payload, 200k presentRwLock<BTreeMap<u64, ...>>13.5 / 13.7 M ops/s1.48x / 1.52xu64 -> 128-byte payload, 200k presentSyncExpanseBytesMap116.6 / 116.4 M ops/s11.09x / 11.10xstring keys, 100k presentSyncExpanseStrMap77.6 / 77.6 M ops/s11.08x / 11.13xstring keys, 100k presentDashMap<Vec<u8>, u64>109.2 / 107.2 M ops/s7.68x / 7.51xstring keys, 100k presentAt 50% read / 50% write — 1→16 threads, read + write ops/s (a mixed-operation rate), then that arm's scaling in run 1 / run 2:SyncExpanseMap [u64 keys, 1M present]: 18.9 → 49.0 → 63.4 M ops/s (run 1) · 3.35x / 3.53xSyncExpanseSet [u64 keys, 1M present]: 34.5 → 66.7 → 126.7 M ops/s (run 1) · 3.67x / 3.73xSyncExpanseBlobMap [u64 -> 128-byte payload, 200k present]: 11.9 → 20.4 → 13.2 M ops/s (run 1) · 1.11x / 1.13xSkipMap<u64, (Vec<u8>, u32)> [u64 -> 128-byte payload, 200k present]: 2.2 → 6.9 → 17.8 M ops/s (run 1) · 8.25x / 8.23xSyncExpanseBytesMap [string keys, 100k present]: 4.9 → 14.5 → 40.0 M ops/s (run 1) · 8.26x / 8.17xSyncExpanseStrMap [string keys, 100k present]: 5.8 → 20.3 → 53.5 M ops/s (run 1) · 9.17x / 9.23xDashMap<Vec<u8>, u64> [string keys, 100k present]: 10.6 → 33.2 → 82.7 M ops/s (run 1) · 7.79x / 7.91xMeasured: reference host -- 12th Gen Intel(R) Core(TM) i9-12900F, pin 0-15 · runs 36658309874 and 36661955960, ref f9853201threads 1,4,16, 18 interleaved rounds of 500 ms windows, largest foreign busy CPUs over a group 0.09 across both runs
YCSB workloads A-F throughputYCSB WORKLOADS A–F THROUGHPUTMops/s · higher is better · N = 100,000, Zipfian theta = 0.99, 128B blobs, uniform-random shuffled, seed 0x1234_5678_9ABCExpanseMap (u64)ExpanseBlobMap (128B)BTreeMap (128B)SkipMap (128B)Workloads A–D and F share one zero-based axis; Workload E has its own, an order of magnitude lower.Workload A50% Read / 50% Update38.7317.9414.043.09Expanse 2.76xWorkload B95% Read / 5% Update47.4130.2715.635.15Expanse 3.03xWorkload C100% Read48.9431.8415.865.68Expanse 3.09xWorkload D95% Read-Latest / 5% Insert65.8334.7917.797.29Expanse 3.70xWorkload F50% Read / 50% Read-Modify-Write33.4515.4815.052.75Expanse 2.22xWorkload E, separate axis (max 1.576 Mops/s) — Plotted on its own axis: every arm is an order of magnitude below A-D/F, and BTreeMap wins.Workload E95% Short Range Scan / 5% Insert0.8670.6971.5760.332BTreeMap 1.82xMeasured: reference host -- Intel i9-12900F, 24 threads, 30 MiB L3, Ubuntu 22.04 / kernel 6.8 · run 35419627251 · benches/ycsb.rs, standardized 8-round suite (Refs #1005)The Workload E figure published under #375 is retracted; E is re-measured here and inverts.

Both charts are current measurements on later builds than v0.6.0, from committed result files: concurrency run 1 and run 2 (commit f9853201), and YCSB (commit 21a382f3).

Each YCSB badge compares ExpanseMap holding u64 values with BTreeMap holding 128-byte records, so the two arms do not carry the same payload. With the same 128-byte payload, ExpanseBlobMap against BTreeMap measures 1.278× on A (BCa 95% CI [1.252, 1.318]), 1.936× on B [1.918, 1.957], 2.008× on C [1.969, 2.030], 1.955× on D [1.937, 1.971] and 1.029× on F [1.025, 1.035], and loses Workload E at 0.442× [0.441, 0.443], from the same result file.

Across different access patterns, performance reflects the structural advantages of expanse partitioning:


Isn’t a hash table just as good?

In 2003 Sean Barrett asked exactly this question in A Performance Comparison of Judy to Hash Tables. He benchmarked JudyL against a hash table he wrote himself with the same interface, 32-bit keys and values: about 200 lines of C, secondary hashing, doubling at 65% full, on a 700 MHz Pentium III laptop. What he found:

His conclusion was that Judy’s compactness does not buy it an enormous speed advantage, and that an hour or three spent on a standard 200-line hash table holds up against 20,000 lines of Judy. His method is the one I wanted to hold Expanse to: if performance is what matters, “the only thing to do is measure performance, not space.”

So I measured, and then measured again with the gaps he would have pointed at closed: lookups in random order, keys built to hurt a trie, every population from 16 keys to 4 million, and his churn test. The second round took back the one lookup win I had published.

Random keys: the hash table still wins, by about his factor of 2. Against hashbrown, the SwissTable implementation behind Rust’s HashMap, Expanse reaches 0.501× its lookup throughput on uniform random 64-bit keys at 500,000 entries, BCa 95% CI [0.495, 0.510], and 0.498× in a second run ( results). On lookups for keys that are not there it is 0.250×. Against std HashMap at a million random keys, an Expanse lookup takes 3.3 times as long; the two committed runs span [3.315, 3.375] ( table). std’s default hasher is SipHash, built to resist collision attacks and slower than hashbrown’s default, which is why the two ratios differ.

Modernizing the trie does not get around this. On random lookups at a million keys, Expanse takes 1.031× stock libJudy’s time [1.024, 1.038] ( results). Barrett also wrote that there were not many ways left to improve Judy, but a lot of room to improve hash tables.

Structured keys: the trie wins only when the lookups come in key order. An earlier version of this section said the trie wins on structured keys, at 1.740× hashbrown on dense sequential keys and 1.990× on clustered ones. Those lookups walked the keys in the order they were inserted. Shuffle the same lookups over the same build and the result flips ( results):

Both runs agree. In insertion order Expanse runs at 134.6 million lookups a second on sequential keys; shuffled, at 65.1 million, while hashbrown gets slightly faster. Consecutive lookups landing in the same trie leaf is the likely reason, but no cache counter was taken, so that is a hypothesis. The insertion-order ratio also moved between two pairs of runs on the same code (1.532× and 1.384×), and the shuffled one did not, so the shuffled figure is the one to quote. Sequential keys give you a trie that is fast when you read them back in order: a scan, a replay, a cursor. Looked up at random, they are just keys, and the hash table wins.

Keys built to hurt a trie, and small populations: the hash table wins those too. Barrett listed key patterns that should be bad for a digital tree. Against hashbrown at 500,000 keys, one ASCII character per byte runs at 0.187× and byte-swapped dense keys at 0.498× ( same table). He found the hash table winning below 10,000 entries. Measured at every population from 16 to 4,194,304 keys, hashbrown is faster on hit lookups at every one of them, on random, sequential and byte-swapped keys (a few sequential cells tie in one of the two runs) ( population sweep). There is no crossover to find.

Churn: his result again. Hold the population constant and replace the oldest keys in batches of 128, and hashbrown wins every cell: an insert plus a remove costs Expanse 9× hashbrown’s time on random keys at 100,000 (0.111×) and about 1.1× on sequential keys at 4 million (0.880×) ( results). Barrett found the same. Against Rust’s BTreeMap, the ordered structure Expanse actually competes with, Expanse wins every churn cell by 1.76× to 2.47×, and every lookup cell at 500,000 keys; its one lookup loss in the sweep is at 32 sequential keys, one past the size of its root leaf.

Memory: the one place structured keys still pay off. At 500,000 entries with 8-byte values, exact heap accounting identical in every run ( results):

The population sweep shows the whole curve. hashbrown saws between 19.6 and 35.7 bytes per key as its table fills and doubles. On sequential keys Expanse falls below it from about 5,600 keys up, reaching 8.6 bytes per key at 4 million. On random keys Expanse is smaller only near the tops of hashbrown’s sawtooth. And small maps are Expanse’s worst case: 1,296 bytes per key at 16 keys, the largest of the three structures by an order of magnitude below about 1,000 keys.

What Barrett didn’t measure is where Expanse earns its size.

So the honest answer:

The hashbrown lookup, population-sweep and churn figures are run 1 of two committed runs on the reference host (Intel i9-12900F, CPUs 0–15, performance governor), means of 9 rounds with BCa 95% intervals, measured at Expanse commits 4659016f, 0c2152c4 and cc70a809; run 2 is beside each in the same directory. The memory and tail-latency figures are from commit 2f82cd07 (powersave governor), and the 500,000- and 100,000-key memory figures reproduced byte for byte in the new runs. The std HashMap and libJudy figures are from commit 82eb56af.


Real-World Use Cases in Systems Engineering

Having spent years building high-throughput infrastructure at TubeMogul and Adobe—where a few nanoseconds of p99 latency or a 20% memory bloat cascades across thousands of servers—these are the specific patterns where digital tries shine:

1. RocksDB Pluggable MemTable (rocksdb-expanse)

Standard LSM-tree storage engines, such as RocksDB, use SkipLists for their in-memory MemTables because SkipLists allow lock-free concurrent inserts. But SkipLists pay a variable-height tower of forward pointers per node — ~18.7 bytes of indexing overhead per entry against Expanse’s 13.2 ( results) — and have poor spatial cache locality.

By implementing RocksDB’s MemTableRep interface on top of Expanse, the standardized YCSB suite (100k keys, Zipfian θ=0.99, 128-byte records) measures ( results):

2. CIDR Subnet Routing & Network Filtering

IPv4 and IPv6 subnets (e.g., 192.168.1.0/24 or /48 IPv6 blocks) are natural prefix paths in a 256-ary digital trie. Longest Prefix Match wants exactly the descent the trie already does: bounded at 4 hops for IPv4 and 8 for 64-bit keys, no hash collisions, no tree rotations, no allocation on the read path. I have not built the LPM layer yet, so take this one as a design fit rather than a benchmark.

3. Database MVCC Visibility Maps

In modern transactional engines (PostgreSQL, MySQL InnoDB, CockroachDB), tracking active transaction IDs (xid) for Multi-Version Concurrency Control (MVCC) requires a low-overhead, concurrent bitset. SyncExpanseSet lets background transactions commit and register while concurrent readers check row visibility without taking a lock on the common path. In v0.6.0, writers still serialize against each other on one mutex; since v0.7.0, writers on disjoint subtrees run in parallel.


Getting Started with Expanse

Expanse is open source under dual MIT / Apache-2.0 licensing. Each release is also archived on Zenodo; to cite the software, use the concept DOI 10.5281/zenodo.22152112, which always resolves to the latest release.

Rust

Add expanse-trie to your Cargo.toml:

[dependencies]
expanse-trie = "0.18.0"
use expanse_trie::ExpanseMap;

let mut map = ExpanseMap::new();
map.insert(1042, 500);

if let Some(val) = map.get(1042) {
    println!("Found value: {}", val);
}

// Ordered range navigation in O(depth)
for (key, val) in map.range(1000..=2000) {
    println!("{}: {}", key, val);
}

C / Linux Packages (Debian, Ubuntu, Fedora, RHEL)

Install prebuilt packages directly from the official repositories:

# Debian / Ubuntu
echo "deb [trusted=yes] https://orieg.github.io/expanse/apt/ stable main" | sudo tee /etc/apt/sources.list.d/expanse.list
sudo apt-get update
sudo apt-get install -y libexpanse1 libexpanse-dev libjudy-compat

# Fedora / RHEL / AlmaLinux
sudo dnf config-manager --add-repo https://orieg.github.io/expanse/rpm/expanse.repo
sudo dnf install -y libexpanse libexpanse-devel libjudy-compat

Compile against the modern C API (expanse.h) or drop-in legacy API (Judy.h):

#include <stdio.h>
#include <expanse.h>

int main() {
    expanse_map_t *map = expanse_map_new();
    expanse_map_insert(map, 1042, 500, NULL);

    uint64_t val = 0;
    if (expanse_map_get(map, 1042, &val)) {
        printf("Retrieved key 1042 -> %llu\n", (unsigned long long) val);
    }
    
    expanse_map_free(map);
    return 0;
}
gcc -O3 main.c -lexpanse -o main
./main

Language bindings and target platforms are available across the ecosystem:


Looking Ahead

Building Expanse reminded me that good algorithmic ideas don’t expire—sometimes they just get trapped in the implementation constraints of the era in which they were born.

Doug Baskins’s insight that digital tries partitioned by expanse could outperform comparison-based trees was ahead of its time in 2002. Rebuilding that vision for modern 64-bit microarchitectures with SIMD vectorization and optimistic concurrency shows how much headroom remains when we design algorithms around the actual physics of modern silicon.

Check out the project on GitHub, explore the live Architecture Visualizer, and let me know your thoughts!


Corrections (2026-11-08). Corrected: the concurrency protocol is blocking optimistic lock coupling, not lock-free; the single-writer description is scoped to v0.6.0, the version this post covers, with a note on the concurrent writers that shipped in v0.7.0; the C ABI claim is now scoped to the legacy symbols on 64-bit builds instead of “100%”; “memory-safe” is replaced by what is actually checked, since Expanse uses audited unsafe and has a published advisory ( GHSA-4wgg-rc8x-w9r2). Removed benchmark figures that were withdrawn or are not in a committed result file; the concurrency and YCSB charts are replaced with current measurements from committed result files, and the stdlib comparison chart, whose figures had none, is replaced by a lookup chart from two committed runs that shows only the orderings both runs agree on.