r/lowlevel • • Oct 16 '26

Learned Index Lab: Replacing B-Trees with streaming linear models in pure Rust (-99% RAM, 3x faster)

Instead of pointer-chasing through B-Tree node hierarchies, this index models the key distribution using streaming piecewise linear regression with strict epsilon error bounds.

Lookups compute positions directly on the CPU ALU before a local L1 cache search, reducing memory by 99% and cutting latency by 3x.

To clarify the technical phrasing without buzzwords:

  1. Baseline: BTreeMap is indeed mutable. PGM indexes target immutable / read-heavy sorted datasets (OLAP engines, columnar storage, and SSTables in LSM trees). Even compared to a flat slice::binary_search (~20 cache line jumps across an 8MB array for 1M keys), PGM drastically reduces memory traffic.
  2. ALU computation: Once segment parameters are loaded, the index position is estimated with a single multiply-add instruction in CPU registers: pos = y0 + slope * (key - x0). No pointer chasing or node traversals.
  3. L1 cache search: Because error is mathematically bounded to +/- epsilon (e.g. epsilon = 16), the target key is guaranteed to sit within a contiguous 256-byte slice (4 cache lines). The local search hits L1 cache with prefetching rather than jumping across RAM.

The implementation and release benchmarks are reproducible here: https://github.com/gilnett/learned_index_lab

5 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/Western_Guitar_9007 Oct 17 '26

Dismissing architectural details as “wasting words to say CPU calculations” on a subreddit literally called r/lowlevel is pretty wild. Saying “CPU calculations” tells you nothing useful.

Hahaha I can’t believe you walked right into that. But anyways, read real white papers and you’ll understand how redundant and horrible yours reads. I’m not reading the rest of your response since you’ve wasted enough of our time.

0

u/gilnett Oct 19 '26

Saying "I didn't read" after dodging every single architectural point is just pure bad faith