Skip to content

beatree: add Options::prepopulate_leaf_cache - #953

Draft
citizen-stig wants to merge 3 commits into
thrumdev:masterfrom
citizen-stig:nikolai/prepopulate-leaf-cache
Draft

citizen-stig wants to merge 3 commits into
thrumdev:masterfrom
citizen-stig:nikolai/prepopulate-leaf-cache

Conversation

@citizen-stig

@citizen-stig citizen-stig commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

After a restart the beatree leaf cache is empty, so the first sessions pay for cold leaf reads. NOMT can already warm the page cache on startup (Options::prepopulate_page_cache). This adds the equivalent for the leaf cache.

Changes

  • New Options::prepopulate_leaf_cache(bool), default false.
  • When it is enabled, Nomt::open calls Store::prepopulate_leaf_cache(commit_concurrency) → Tree::prepopulate_leaf_cache. This collects leaf page numbers from the bottom-level branches in key order, up to LeafCache::capacity(), then reads and inserts them on commit_concurrency scoped threads.
  • Helpers: Index::branches() and LeafCache::capacity().
  • New test nomt/tests/prepopulate_leaf_cache.rs: it writes more leaves than a 1 MiB cache holds, reopens with the option on, and reads every value back.

Limitations:

  • Leaves are chosen in key order (the first capacity leaves), not by how often they're used. That helps most when the working set is small enough to fit, or is clustered at the start of the key space.
  • LeafCache::insert does not evict, and page numbers are spread across shards by hash. So a shard can briefly hold more than its share until regular eviction runs.
  • Nomt::open blocks until the reads finish: up to leaf_cache_size MiB of I/O.

Performance impact

TODO: to be filled in after benchmarking (startup time and the first sessions after a reopen).

citizen-stig and others added 3 commits October 21, 2026 10:39
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017wb3qFhAoTArSEcSTGVDCu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant