r/programming • u/gilnett • 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_labInstead 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
View all comments
Show parent comment
2
u/gilnett Oct 18 '26
Not easily as a drop-in replacement. SQLite is deeply wired around 4 KB disk pages, in-place random writes, and page-level caching in
btree.c. Learned indexes expect flat, contiguous sorted data, so adapting SQLite's transactional write engine would require a massive rewrite.The practical workaround would be a custom SQLite Virtual Table. If your dataset is mostly static or read-only (like pre-packaged mobile databases), a virtual table can index flat sorted data with a learned index in memory, bypassing SQLite's B-Tree memory overhead while keeping regular SQL queries working