r/computerscience • u/gilnett • Oct 18 '26
Discussion Replacing B-Trees with streaming linear models (PGM): cache locality and bounds in practice
Traditional B-Trees waste substantial CPU cycles on pointer chasing across node levels, causing avoidable cache misses on modern architectures. The PGM-index approach (Ferragina & Vinciguerra, VLDB 2020: https://www.vldb.org/pvldb/vol13/p1162-ferragina.pdf) addresses this by modeling key distributions through streaming piecewise linear regression with strict +/- epsilon error bounds.
Instead of traversing tree nodes, key rank is predicted directly on the ALU (y = ax + b), bounding the local search window so that it fits entirely within L1 cache. The construction runs in a single O(N) streaming pass with zero external solvers.
I built a pure Rust reference implementation (v0.2.0) with zero dependencies to benchmark this against std::collections::BTreeMap across 1M keys: https://github.com/gilnett/learned_index_lab. Benchmarks across uniform and skewed distributions show a 99.9% reduction in index memory (~48 KB vs 45 MB) and 3x to 4.5x lower lookup latency.
While transactional engines still rely on B-Trees for in-place page writes, learned models provide significant advantages for read-heavy or immutable storage layouts (such as LSM SSTables and columnar stores) where pointer overhead is pure waste.
Has anyone here benchmarked or worked with learned data structures in storage systems? How do you approach optimal epsilon tuning when key distributions are non-uniform or unpredictable?
View all comments
Show parent comment
1
u/gilnett Oct 19 '26
Thanks a lot for the links. I'm going to look through them in detail and see if there's anything I can add to my roadmap to improve the project and benchmark the differences