Skip to main content

Crate embed_btree

Crate embed_btree 

Source
Expand description

§embed-btree

We provide a BTreeMap for single-threaded long-term in-memory storage. It’s a cache aware b+tree:

  • Nodes are filled up in 4 cache lines (256 bytes on x86_64).
    • Capacity in compile-time determined according to the size of Key, Value.
    • Reduce memory fragmentation by alignment.
  • Optimised for numeric key
    • Respecting numeric space for sequential insertion.
    • Reduce latency for sequential insertion.
  • Faster iteration and teardown
  • Limitation:
    • K should have clone (for propagate into the InterNode during split)
    • K & V should <= CACHE_LINE_SIZE - 16
      • It make sure InterNode can hold at least two children.
      • If K & V is large you should put into Box, for room saving, and for the speed to move value
  • Special API:
    • Peak and move to previous/next Entry (for modification).
    • Alter key of an OccupiedEntry.
    • Batch remove with range.
    • Movable Cursor (for readonly)

Compared to std::collections::btree (as of rust 1.94):

  • The std impl is pure btree (not b+tree) without horizontal links. Each key store only once at either leaf and inter nodes.
  • The std impl is optimised for point lookup.
  • The std impl has fixed Cap=11, node size varies according to T. (For T=U64, size is 288B for InterNode and 192B for LeafNode)
  • The std cursor API is still unstable (as of 1.94) and relatively complex to use.

benchmark

platform: intel i7-8550U, key: u32, value: u32, rust 1.92.

Measured in million ops for different size of dataset:

insert_seqbtreestd
1k88.95620.001
10k75.29116.04
100k45.95911.207
insert_randbtreestdavl(box)avl(arc)
1k21.31117.79211.1729.5397
10k14.26811.5876.36695.651
100k5.48143.06910.780.732
get_seqbtreestd
1k59.44834.248
10k37.22527.571
100k30.7719.907
get_randbtreestdavl(box)avl(arc)
1k47.3327.65124.25423.466
10k19.35816.86811.77110.806
100k5.25843.25691.44231.2712
remove_randbtreestd
1k20.96515.968
10k16.07311.701
100k5.02143.0724
iterbtreestd
1k1342.8346.8
10k1209.4303.83
100k152.5751.147
into_iterbtreestd
1k396.07143.81
10k397.0581.389
100k360.1856.742

Re-exports§

pub use various_map::VariousMap;
pub use btree::BTreeMap;

Modules§

btree
B+Tree Map - A in memory cache-optimized B+Tree for single-threaded use.
various_map
VariousMap: Provide a tempoary map optimise for empty or one condition, to delay allocation.

Macros§

print_log
logging macro for development
trace_log
logging macro for development

Constants§

CACHE_LINE_SIZE
Cache line size in bytes