Skip to content

test: add comprehensive node cache correctness tests for BTreeMap#431

Open
maksymar wants to merge 23 commits intomainfrom
maksym/btm-tests
Open

test: add comprehensive node cache correctness tests for BTreeMap#431
maksymar wants to merge 23 commits intomainfrom
maksym/btm-tests

Conversation

@maksymar
Copy link
Copy Markdown
Contributor

@maksymar maksymar commented Apr 3, 2026

This PR adds new tests covering node cache correctness gaps.

The existing suite had minimal cache-specific coverage — one proptest at a single cache size.

These tests verify:

  • cache coherence across multiple cache sizes (including non-power-of-two)
  • structural scenarios (splits, merges, rotations)
  • path-reuse patterns (get-then-remove, peek-then-pop)
  • read-warm-write-read cycles
  • cache resize mid-use
  • and forward-looking tests for the save-and-cache-node optimization

maksymar added 10 commits April 3, 2026 11:07
Run the same randomized operation sequence at cache sizes
0, 1, 4, 16, 64, 256 to catch size-dependent correctness bugs.
Each variant uses 3 proptest cases to keep total runtime reasonable.
Run a deterministic operation sequence (insert, overwrite, get, remove,
pop, iterate) with cache=0 and cache=1/4/16/64/256, assert all return
values are identical. This is the strongest cache invariant: the cache
must be invisible to the API.
Add 8 deterministic tests that exercise specific cache-interaction
patterns with small caches (0, 1, 4 slots) to maximize collision
and eviction pressure:

- insert-then-get
- overwrite-then-get (the pattern that broke save_and_cache_node)
- split-then-get-all
- merge-then-get-remaining
- sequential-inserts-then-gets
- interleaved-insert-get-remove
- pop correctness with cache
- first/last_key_value during mutations

Each test runs at multiple cache sizes via run_with_various_cache_sizes.
Add 3 tests designed to catch stale-cache-after-save bugs if
save_and_cache_node is implemented in the future:

- saved leaf other entries readable (lazy ByRef survives save)
- overwrite varying value sizes (layout changes vs cached offsets)
- rebalance then read siblings (rotation/merge vs cached neighbors)

All pass today with invalidate-on-save and serve as acceptance
criteria for the optimization.
Add cached variants of 7 important existing tests at cache=1 (max
collisions) and cache=64 (warm cache). Uses u32/u64 types only to
keep runtime bounded — the originals already cover the full type grid.

Tests covered: insert+get, insert overwrites, insert+remove many,
pop_first, pop_last, first_key_value, last_key_value.
Verify the cache is actually used and metrics are consistent:
- hits > 0 after get-heavy workload with cache enabled
- hits == 0 and misses == 0 with cache disabled (0 slots)
- metrics reset after clear_new()
…ring

- Add non-power-of-two cache sizes (3, 7, 50) to proptests,
  run_with_various_cache_sizes, and the equivalence test. Users can
  pass any value to with_node_cache, so correctness must not depend
  on power-of-two alignment.

- Cache metrics tests now explicitly call node_cache_clear_metrics()
  before the measured workload so counters reflect only that workload.

- Improve doc comments on NodeCacheMetrics and node_cache_clear_metrics
  to explain that counters accumulate and must be cleared before
  measuring a specific workload.
Add 5 tests that exercise the pattern: populate tree, read all keys
(warming the cache), modify the tree, then read again. This catches
bugs where a write invalidates only the nodes it touches but leaves
other (now-stale) nodes in the cache from the read phase.

- read-warm then insert (with splits)
- read-warm then overwrite
- read-warm then remove (with merges)
- read-warm then pop_first/pop_last
- repeated read-write cycles
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

canbench 🏋 (dir: ./benchmarks/btreemap) 8408234 2026-04-04 08:48:00 UTC

./benchmarks/btreemap/canbench_results.yml is up to date
📦 canbench_results_btreemap.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 252 | regressed 0 | improved 0 | new 0 | unchanged 252]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 252 | regressed 0 | improved 0 | new 0 | unchanged 252]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 252 | regressed 0 | improved 0 | new 0 | unchanged 252]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

canbench 🏋 (dir: ./benchmarks/btreeset) 8408234 2026-04-04 08:46:56 UTC

./benchmarks/btreeset/canbench_results.yml is up to date
📦 canbench_results_btreeset.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 100 | regressed 0 | improved 0 | new 0 | unchanged 100]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 100 | regressed 0 | improved 0 | new 0 | unchanged 100]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 100 | regressed 0 | improved 0 | new 0 | unchanged 100]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

canbench 🏋 (dir: ./benchmarks/vec) 8408234 2026-04-04 08:46:47 UTC

./benchmarks/vec/canbench_results.yml is up to date
📦 canbench_results_vec.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

canbench 🏋 (dir: ./benchmarks/io_chunks) 8408234 2026-04-04 08:47:24 UTC

./benchmarks/io_chunks/canbench_results.yml is up to date
📦 canbench_results_io_chunks.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 18 | regressed 0 | improved 0 | new 0 | unchanged 18]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 18 | regressed 0 | improved 0 | new 0 | unchanged 18]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 18 | regressed 0 | improved 0 | new 0 | unchanged 18]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

canbench 🏋 (dir: ./benchmarks/nns) 8408234 2026-04-04 08:46:46 UTC

./benchmarks/nns/canbench_results.yml is up to date
📦 canbench_results_nns.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 16 | regressed 0 | improved 0 | new 0 | unchanged 16]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

canbench 🏋 (dir: ./benchmarks/memory_manager) 8408234 2026-04-04 08:46:39 UTC

./benchmarks/memory_manager/canbench_results.yml is up to date
📦 canbench_results_memory-manager.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 3 | regressed 0 | improved 0 | new 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 3 | regressed 0 | improved 0 | new 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 3 | regressed 0 | improved 0 | new 0 | unchanged 3]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

maksymar added 5 commits April 3, 2026 11:40
- get_miss: non-existent keys with warm cache
- get_then_remove: get warms path, remove modifies same path
- get_then_insert: get warms path, overwrite modifies same path
- contains_then_remove: contains warms path without reading value
- peek_then_pop: last_key_value/first_key_value then pop
- deeper_tree: 2000 entries for deeper cache pressure
- cache_resize_mid_use: resize cache between operations (16 → 1 → 0 → 64),
  verify correctness after each resize
- cache_partial_iter_then_mutate: partial iteration warms cache, then
  mutations modify the tree, then full iteration must be consistent
@maksymar maksymar changed the title test: improve BTreeMap tests test: add comprehensive node cache correctness tests for btreemap Apr 3, 2026
@maksymar maksymar marked this pull request as ready for review April 3, 2026 10:09
@maksymar maksymar requested a review from a team as a code owner April 3, 2026 10:09
@maksymar maksymar enabled auto-merge (squash) April 3, 2026 10:09
Mix get, contains_key, first/last_key_value on the same cached nodes
between bulk overwrites across multiple rounds.
@maksymar maksymar changed the title test: add comprehensive node cache correctness tests for btreemap test: add comprehensive node cache correctness tests for BTreeMap Apr 3, 2026
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