Repository navigation
perf(frag-reuse): run-optimize the remap payload and keep it cheap to rank - #69
Conversation
The fragment-reuse payload records which row addresses a compaction moved, as a serialized RoaringTreemap. Compaction rewrites long contiguous spans, but the treemap is written without ever calling `optimize()`, so those spans are stored as dense bitmap containers at one bit per row. On a real payload here that is 88 MB describing 676M addresses, essentially all of it bitmap containers (676M bits is 84.6 MB). The same information as run containers is a few bytes per span. The payload is read on every index open, so this shrinks both the object and the deserialize that follows it. No format change: run containers are already produced today by the binary-copy path, which reaches `Store::Run` through `insert_range`. Co-authored-by: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit dec9486)
The preceding commit run-optimizes the address set before serializing it, but shipped without a test. This asserts both the mechanism and the outcome: every per-fragment bitmap in the deserialized payload holds exactly one run container and nothing else, and the payload is more than 20x smaller than the same addresses re-inserted, which is the encoding they would carry unoptimized. Fragments hold 5,000 rows deliberately. Below roaring's 4096-element array limit an unoptimized store is an array container, not the dense bitset `optimize()` exists to replace, so a smaller fragment would exercise the wrong path. The size bound is computed in the test rather than hardcoded, so it states the guarantee instead of a magic number and survives changes to fragment count or roaring's thresholds. Verified the test is not vacuous: with `row_addrs.optimize()` removed it fails with `left: (0, 0, 1)` against `right: (1, 0, 0)` -- one 64 KiB dense bitset holding 5,000 values. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…or lookup cost (#45) `CompactRowAddrRemap::get` reaches `RoaringBitmap::rank`, which sums `len()` over every container below the target. For bitmap and array containers `len()` is O(1) -- a cached field and a `Vec::len` respectively -- but for run containers it rescans the interval list. `GroupRemap::new` cloned the deserialized payload's bitmaps as they arrived, so it inherited whatever encoding was on disk, and compaction deliberately run-optimizes the address set before writing it. `optimize` chooses by serialized size, which is the right objective for a payload and the wrong one for a structure that will be ranked. Where the address set has deletion holes -- many short runs -- inheriting that encoding makes each lookup O(#containers x #runs), so it scales with fragment width in rows, when this structure exists to be bounded by fragment count. Stripping unconditionally is not the answer either: a fragment rewritten whole is one contiguous run per container, which ranks as cheaply as a cached read and costs six bytes against a bitmap container's fixed 8 KiB. So the encoding is now chosen per bitmap by run density, keeping whichever is cheaper to rank. The serialized payload is untouched, so the on-disk win that motivated run-optimizing is unaffected. Where stripping happens the resident bitmaps grow -- bounded by fragment count, and confined to the case where run encoding was the bulkier option anyway. `MAX_RUNS_PER_CONTAINER` sits at the low end deliberately. The cheap regime is one run per container, and the error is asymmetric: keeping runs that should be stripped costs a term that grows with the dataset, while stripping runs that should be kept costs a small constant. The size of the win depends on how often lookups hit the reuse index at all, since a miss returns before any rank happens: substantial on hit-heavy loads over wide fragments, a smaller constant factor where most probed addresses fall outside the index's fragments. Two tests, one per branch. Each asserts the payload arrives run-encoded before checking the outcome, so neither can pass vacuously, and that the choice moves no address. Both were verified to fail under the opposite mutation. Co-authored-by: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit d644125)
|
Rebase note. Superseded upstream; do not carry this forward and do not raise it. Both halves are on
A release branch cut from an upstream commit at or after lance-format#8688 that also carries the current |
Related
Ports
dec9486a6(#39) andd644125a1(#45) fromrelease-8.0.0, on top of #59. #39 and #45's production change applied unchanged; #45's tests were re-seated around the tests #59 added to the same module.What
Compaction records the row addresses it moved as a serialized
RoaringTreemapin the fragment-reuse index, read on every index open. Contiguous spans were stored as dense bitmap containers at one bit per row — 88 MB for 676M addresses on a real payload — so the set is now run-optimized before it is written.That encoding must not then become a lookup cost.
CompactRowAddrRemap::getreachesRoaringBitmap::rank, which sumslen()over every container below the target: a cached field for bitmap containers, an interval rescan for run containers. Inheriting the on-disk encoding would make each lookup O(#containers x #runs) — scaling with fragment width in rows, for a structure whose point is to scale with fragment count. The resident encoding is therefore chosen per bitmap by run density: a fragment rewritten whole stays run-encoded, one run per container being both cheaper to rank and 6 bytes against a bitmap container's fixed 8 KiB, while a set peppered with deletion holes has its runs stripped. The serialized payload is untouched either way.MAX_RUNS_PER_CONTAINERsits at the low end deliberately: keeping runs that should be stripped costs a term that grows with the dataset, stripping runs that should be kept costs a small constant.The payload win is on the
appendpath only; the binary-copy path already emits run containers viainsert_range, whereoptimize()is a no-op.Testing
New tests:
test_captured_row_addrs_are_run_optimized— the payload reaches disk run-encoded. perf(frag-reuse): run-optimize the compaction row-address set before writing it #39 shipped without a test. Removingrow_addrs.optimize()fails it withleft: (0, 0, 1)againstright: (1, 0, 0): one 64 KiB dense bitset for 5,000 values. Fragments hold 5,000 rows because below roaring's 4096-element array limit an unoptimized store is an array container, not the dense bitsetoptimize()replaces; the size bound is computed in-test from the same addresses re-inserted, not hardcoded.test_resident_bitmaps_are_not_run_encoded— runs are stripped where they are dense. Makingshould_strip_runsalways answer false fails it withfragment 0 kept 4 run containers; rank would pay O(containers x runs) per lookup.test_run_encoding_kept_when_runs_are_few— the other side: one run per container is left alone.test_no_run_containers_needs_no_special_case— pins the absent zero guard inshould_strip_runs, whose byte arithmetic would otherwise be a subtraction waiting to underflow.Compatibility
No format change: run containers are already produced by the binary-copy path, and
roaringis pinned at 0.11.4 across release-8, -9 and -10, so every reader in range deserializes them. Resident bitmaps grow where runs are stripped, bounded by fragment count and confined to the case where run encoding was the bulkier option anyway.