Skip to main content
← CONCEPTS / ALGORITHMS & DATA STRUCTURES
An end-to-end domain learning journey

Adaptive Radix Trees (ART): Path Compression, SIMD
Node Layouts & Optimistic Lock Coupling.

Adaptive Radix Trees shrink trie memory by 10x+ using four dynamically sized node layouts (Node4, Node16, Node48, Node256) plus path compression, and scale to 64+ cores via Optimistic Lock Coupling.
Start the journey5 sections· Last modified Nov 26, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When an in-memory ordered index stalls on B+Tree comparison misses, use ART with SIMD Node16 scans and OLC version validation.

TL;DR30-second simplified summary
▾

ART adapts fanout across Node4, SIMD Node16, indexed Node48, and direct Node256 while collapsing single-child chains. OLC lets readers traverse without dirtying cache lines.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Tries & Radix Trees
Know how prefix trees branch on key bytes instead of comparing whole keys, giving O(k) lookup time independent of dataset size N.
CPU Cache Lines & SIMD
Understand that a single 64-byte cache line miss costs ~60–100 ns, while SSE2/AVX2 can compare 16 bytes in a single CPU instruction.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

P · Problem & Why Classic Tries and B+Trees Stall.

If you index 100 million 64-bit integers in a standard 256-way radix trie (8 levels, 1 byte per level), every sparse inner node allocates 256 * 8-byte pointers = 2,048 bytes just to store 2 or 3 children.

That wastes >90% of DRAM on null pointers. On the other hand, a B+Tree has depth log_B(N) (~4–5 levels for 100M keys), but at every level it binary-searches 64–256 keys, causing unpredictable branch mispredictions and repeated full-key comparisons (especially costly for variable-length strings).

Index Memory & Cache

256-Way Trie Bloat vs. Adaptive Radix Tree (ART)

Before · Naive 256-Way Trie
  • 2 KB per node even for 2 children
  • 95%+ null pointers in DRAM
  • Deep chains on shared prefixes
After · Adaptive Radix Tree (ART)
  • Node4/16/48/256 shrink with fanout
  • Path compression collapses chains
  • 16-way SIMD compare in 1 cycle
02
L4 · FUNDAMENTALS

R · Representation: Node4, Node16, Node48 & Node256.

Instead of one giant node struct, ART uses four node sizes and promotes/demotes a node as children are inserted or deleted.

Node4 (<=4 children) fits in a single 64-byte cache line using sorted key bytes. Node16 (5–16 children) stores up to 16 key bytes and uses _mm_cmpeq_epi8 + _mm_movemask_epi8 to test all 16 bytes in parallel. Node48 (17–48 children) uses a 256-byte lookup array mapping byte -> slot index [0..47], avoiding 256 * 8B = 2 KB pointers. Node256 (49–256 children) uses a direct children[byte] array for O(1) indexing.

Adaptive Node Layouts

Node4 -> Node16 (SIMD) -> Node48 (Byte Index) -> Node256 (Direct)

03
L5 · APPLIED DESIGN

I · Invariant: Lazy Expansion & Path Compression.

Suppose two keys are /api/v1/users/1001 and /api/v1/users/1002. A naive trie creates 14 single-child inner nodes just for /api/v1/users/100.

ART eliminates those nodes with two rules: (1) Lazy Expansion—never create inner nodes for a single leaf; store the full suffix in the leaf until a second key shares a prefix. (2) Path Compression—store the common prefix bytes directly in the inner node header so lookup skips all shared bytes in one memcmp.

Prefix Skipping

Path-Compressed Traversal & Leaf Verification

Lookup(key)Node4(prefix='app/')Node16 (SIMD)Leaf (full key)1. Skip 4-byte prefix 'app/'2. Branch on byte 'l'3. SIMD match byte 'e'4. Verify full key & return value
04
L5 · APPLIED DESIGN

M · Mechanics at Scale: Optimistic Lock Coupling (OLC).

Even a shared reader-writer lock (pthread_rwlock) writes a reader count to memory on every read, causing CPU cache-line bouncing across cores.

With Optimistic Lock Coupling (OLC), each ART node carries an atomic 64-bit version_lock_obsolete word: bit 0 is the write lock, bit 1 marks an obsolete/replaced node, and the upper bits are a monotonic version counter. Readers never write to memory—they load v = node.read_lock_or_restart(), read child pointers, and call node.read_unlock_or_restart(v). If v changed or bit 0/1 was set, the reader simply restarts from the root.

OLC Version Protocol

Optimistic Read Validation vs. Concurrent Writer Bump

unlockedv == currentwriter bumped vLoad Version v(even)Read Child Pointerv Unchanged ->CommitVersion Skew ->Restart
Engineering Decision Framework
Problem
How to scale an ordered in-memory index across 64+ CPU cores with minimal read contention.
Naive Solution
Use a global RWLock or per-node RWLock on every traversal.
Why It Fails
Every reader mutates the lock's atomic counter, invalidating the cache line across all other cores.
Alternatives
Per-node RWLocks vs. Lock-Free Bw-Tree vs. ART + Optimistic Lock Coupling (OLC).
Engineering Decision
Use ART with OLC: version-validated lock-free reads + fine-grained per-node write locks + Epoch-Based Reclamation.
Trade-Offs
Readers never dirty cache lines, at the cost of occasional read restarts under heavy write contention on the same node.
05
L6 · SCALE & TRADE-OFFS

E · Edge Cases, Assumptions & When NOT to Use ART.

ART compares raw unsigned bytes from left to right. If you insert signed integers (-5 vs +5) or variable-length strings where one key is a prefix of another ('app' and 'apple'), naive byte ordering breaks!

Fix both deterministically: (1) Flip the sign bit on signed integers and store in big-endian byte order so unsigned byte order matches numeric order; (2) Append a 0x00 sentinel byte to variable-length strings (or store leaf pointers with key-length metadata) so no key is a prefix of another.

Key Normalization

Big-Endian Sign-Bit Flip & Null-Terminated Bytes -> ART

Raw Keys (int64 /UTF-8)ingressBig-Endian + SignFlipcomputeART Inner NodesstorageOLC + EBR Guardcontrolorder-preserving bytesbyte-by-byte radixsafe node reclaim
Decision Exercise · Make the Call

You are indexing 50M variable-length UTF-8 strings ('user', 'user_123', 'user_123_pro') in an in-memory ART. Lookups for 'user' fail or collide with 'user_123'. What invariant was violated?

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does ART's Node48 use a 256-byte index array plus 48 child pointers instead of 256 direct pointers?

Recommended Learning Flow