bbtree 为 Rust 数据系统带来更快有序映射
bbtree 是一种新的 Rust 有序映射实现,设计重点是减少查找和插入时的缓存未命中。项目报告称,在四个 LSM-tree 系统中,它替代跳表后的性能提升为 1.37–6.83 倍;在 Turso 数据库索引对比中,插入和索引 SELECT 分别快 2.22 倍和 1.90 倍。报告还展示了从磁盘内存映射 bbtree 的方案,程序重启后无需重建。
报告提供了 bbtree 在存储和数据库系统中的具体集成与基准测试,这些底层结构被用于智能体记忆、RAG 和 KV 存储等 AI 工作负载。
What can it do?
B-trees are the most important data structure in big data systems, a fast b-tree like bbtree benefits everything on top of it: agents memory, LLM training, RAG, KV store, state caching, vector search, and more.
Here we discuss three representative use cases:
- Replace skiplist in LSM-trees. In place of the skiplist of four LSM-trees,
bbtreeis 1.37–6.83× faster. - In-memory database index. In place of Turso's skiplists, inserts are 2.22× and indexed
SELECTs 1.90× faster. - Mmap a bbtree from disk. No rebuild after a restart: the first answer comes 160–2,500× sooner than std's
BTreeMap.
All LSM-trees use an ordered map to hold recent writes in memory, the memtable. In Rust, this ordered map is usually a skiplist, like crossbeam-skiplist.
bbtree can easily replace it and is much faster. A skiplist takes a cache miss for almost every node it visits on its way down; a bbtree lookup touches a handful of cache lines (see How it works, below).