Skip to main content
← CONCEPTS / DATABASES-STORAGE-ENGINES
An end-to-end domain learning journey

Adaptive Radix
Tree (ART).

Balanced comparison trees (B+ Trees, Red-Black Trees) suffer O(log N) pointer-chasing cache misses (~27 DRAM hops at 100M keys), while naive 256-way radix trees waste >98% of RAM on empty child pointers.
Start the journey3 sections· Last modified Nov 27, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When replacing B+ Trees in DRAM engines, use ART with big-endian key encoding so point lookups and range scans avoid O(log N) cache misses.

TL;DR30-second simplified summary
▾

In-memory engines like DuckDB use ART because Node4 (48B) fits in a single 64B cache line and Node16 uses SIMD to compare 16 keys in 1 cycle.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
CPU cache-line geometry (64-byte cache lines and DRAM latency ~60-100 ns)
Core prerequisite: CPU cache-line geometry (64-byte cache lines and DRAM latency ~60-100 ns).
Radix tree (trie) byte-by-byte branching vs. comparison-based B+ Trees
Core prerequisite: Radix tree (trie) byte-by-byte branching vs. comparison-based B+ Trees.
Full walkthrough · 3 stages
01
STAGE 01L4 · FUNDAMENTALS

Adaptive Node Sizing (Node4 / Node16 / Node48 / Node256).

Match physical node capacity to actual child fanout so sparse upper branches fit inside 1-3 CPU cache lines instead of 32 cache lines.

Node4 (<=4children, ~48B)Node16 (<=16children, ~144B +…Node48 (<=48children, ~640B…Node256 (<=256children, ~2KB…grow on 5th childgrow on 17th childgrow on 49th child
02
STAGE 02L4 · FUNDAMENTALS

Path Compression & Lazy Expansion.

Collapse single-child internal chains into an 8-byte optimistic prefix header and defer node allocation for unique leaf suffixes until a second key diverges.

Before · Naive
After · Hardened
class ARTNode:
    def __init__(self, cap=4, prefix=b''):
        self.cap, self.prefix = cap, prefix
        self.keys, self.children = [], []
        self.index_map = None
    def find_child(self, b: int):
        if self.cap <= 16:
            for i, k in enumerate(self.keys):
                if k == b: return self.children[i]
            return None
        if self.cap == 48:
            idx = self.index_map[b]
            return None if idx == 255 else self.children[idx]
        return self.index_map[b]
03
STAGE 03L5 · APPLIED DESIGN

Binary-Comparable Keys & Optimistic Prefix Checks.

Transform signed integers (flip MSB) and floats into big-endian byte order so lexicographical radix order matches numerical order for range scans. [INSERT YOUR BENCHMARK / PROD NOTE] for workload-specific p99 range-scan throughput.

Key Encoding & Cache Footprint

Binary-Comparable Keys & Adaptive Node Layout

Before · Raw Signed Keys / Naive 256-Way Trie
  • Negatives sort after positives (MSB=1)
  • ~163.8 GB RAM / 32 cache lines per node
After · MSB-Flipped Big-Endian + ART Nodes
  • Lexicographical order matches numeric order
  • ~5.5-11.5 GB RAM / 1-3 cache lines per node
Engineering Decision Framework
Problem
How to support both fast O(k) point lookups and ordered range scans on tens of millions of in-memory keys without wasting RAM or suffering O(log N) DRAM cache misses.
Naive Solution
Use a fixed 256-way radix trie for O(k) speed, or a balanced Red-Black / B+ Tree for compact memory.
Why It Fails
A fixed 256-way trie wastes >98% of RAM (~163.8 GB per 100M sparse keys) on empty pointers, while a Red-Black Tree incurs ~27 pointer-chasing DRAM hops at 100M keys.
Alternatives
Compare ART (Node4/16/48/256 + Path Compression) against hash tables (no range scans), in-memory B+ Trees (O(log N) comparisons), and disk-backed B+ Trees/LSM Trees.
Engineering Decision
Use an Adaptive Radix Tree with big-endian binary-comparable key encoding (flipping the MSB on signed integers) for in-memory OLTP/OLAP indexes, and use B+ Trees or LSM Trees for disk-backed SSD engines.
Trade-Offs
Cuts memory by 10x-30x over naive tries and keeps hot branches in 1-3 CPU cache lines, at the cost of managing four node layouts, path compression, and explicit key-order encoding.
Decision Exercise · Make the Call

A Node16 in your ART index receives a 17th distinct child byte. What is the exact memory-efficient transition?

ChoiceWhat it buysWhat it costs
Adaptive Radix Tree (ART)O(k) lookup complexity independent of dataset size N Compact 1-3 cache lines per node with ~5.5-11.5 GB RAM per 100M sparse keys Supports ordered range scans via binary-comparable key encodingHigher implementation complexity across four adaptive node layouts and path compression Requires big-endian MSB-flip encoding for signed integers and floats
Red-Black TreeCompact ~4.8 GB RAM per 100M keys with uniform node size Native key comparison without byte-order transformationO(log N) pointer chasing (~27 DRAM hops at 100M keys) 1 cache line per node hop causes frequent DRAM stalls
Naive 256-Way TrieO(k) lookup complexity with direct 256-slot byte indexing~163.8 GB RAM per 100M sparse keys (>98% wasted pointers) 32 cache lines per node (2,048 bytes) destroys CPU cache locality
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 4
Score: 0/4

Why does ART's Node48 use a 256-byte index array alongside a 48-pointer array instead of a 48-element sorted key array?

Recommended Learning Flow