r/programming • • Oct 16 '26

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

https://github.com/gilnett/learned_index_lab

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.

191 Upvotes

49 comments sorted by

View all comments

10

u/GreatCosmicMoustache Oct 16 '26

cool idea, but does it require you to solve the big optimization problem every time you add a single row?

11

u/gilnett Oct 16 '26

Nah, no solver or ML training at all. It's just a single O(N) streaming pass using basic slope math—takes ~3ms for 1M keys.

For inserts, you wouldn't mutate the sorted array in-place anyway. You either buffer writes in a memtable and build the index on immutable SSTables (LSM style), or you use gapped arrays where only the local segment splits on overflow.

5

u/gilnett Oct 16 '26

That should answer your question, unless I misunderstood what you meant.