Add redb storage backend with time travel support#308
Add redb storage backend with time travel support#308lawless-m wants to merge 2 commits intocozodb:mainfrom
Conversation
Pure Rust, single-file, ACID storage engine using redb 4.0. Implements Storage and StoreTx traits behind the storage-redb feature flag. Supports time travel via check_key_for_validity seek pattern. Uses collect-into-Vec for range scans and seek-per-step for skip scans. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Stream range_scan on read path using redb's 'static Range iterator instead of collecting into Vec (saves allocation, improves scan perf) - Use retain_in for del_range_from_persisted instead of collect-keys-then-delete loop (single pass) - Remove unused collect_range helper Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Benchmark results — redb vs sqlite and reference backendsRan a reproducible backend comparison on branch For a graph database, reads are the top-line metric — traversals, reachability, aggregations, and time-travel snapshots all pound the read path. Writes are bursty batches that can be amortized. redb vs sqlite (head-to-head at 1M rows)
Headlines
Full reference table
Notes on the reference backends:
Reproducingsystemd-run --user --scope -p MemoryMax=12G -p MemorySwapMax=0 -- env \
COZO_TEST_DB_ENGINE=redb \
COZO_BENCH_TT_DIR=/var/tmp/cozo-bench \
COZO_BENCH_TT_BASE=10000 \
COZO_BENCH_TT_MAX_K=100 \
cargo +nightly bench -p cozo --features storage-redb --bench time_travel -- --nocaptureSwap Downstream usageThis backend is already in production use by Flowstone, a Rust knowledge-graph tool that path-deps this fork with |
Summary
Adds a new pure-Rust storage engine using redb 4.0, gated behind a
storage-redbfeature flag. Single-file, ACID, zero C dependencies — fits the same niche as sled but with a more active upstream.StorageandStoreTxtraits on top of redb'sDatabase/WriteTransaction.check_key_for_validityseek pattern used by the memory backend.range_scanstreams redb's'static Rangeiterator instead of collecting into aVecdel_range_from_persistedusesretain_inin a single pass instead of collect-then-deleteTest plan
cargo check -p cozo --features storage-redb— cleancargo test -p cozo --features storage-redbrun on reviewer's side