Repository navigation
Add experimental PIVCO wavelet-tree integer encoding in UNSTABLE - #12103
lwwmanning wants to merge 3 commits into
Conversation
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
Fresh review of bf5f7388. I found no correctness bug, and no malformed file that can cause a panic or an out-of-bounds read. The read path checks tree depth, symbol ranges against the dtype, header order and bounds, rANS states and stream use, sparse indices, and raw_bits lengths. The 80 seeded byte-flip tests back this up. The compute kernels also traced correct, including negative constants, compares at u64::MAX, slices that start mid-block, and null take indices.
This PR adds the vortex.pivco wire ID to the unstable edition, so its format needs a careful manual review before it leaves draft. Two fixes first:
-
Pin the rANS tables in a test for backward compatibility.
compute_bernoulli_freqsbuilds the 16 Bernoulli tables at run time, so they are part of the format. The only test checks their properties (sum 2048, monotone). A later change to that code would silently break files that were already written. Persist the table values in a test, and pin the serialized bytes of one encoded block with each bitmap marker. -
merge_vec_vec_in_place_left,merge_vec_vec_in_place_right,merge_cst_vec_in_placeandmerge_vec_cst_in_placeinsimd/mod.rsare safe functions, but they do not check thatrightholdspopcount(bm, k)bytes. The scalar tail readsr_base.add(rc)with no bound. For example,merge_vec_vec_in_place_left(&[0xFF; 4], 32, 0, &[], &mut [0; 32])reads 32 bytes from an empty slice. The callers indecode.rsandspine.rsalways computek_rightwith a popcount, so no file can reach this. Mark themunsafe fnwith that precondition, or computek_rightinside them.
Format choices that become permanent once a release can read them:
- Slice state (
offset,tree_base_offset,raw_base_word_offset) goes into the metadata. If serialize rebased the headers, this state would stay off the wire. block_shift == 0is read as 12. Writing 12 avoids a permanent alias.- There is no version byte, so only the unused opcodes and marker values are left to extend the format.
- Padding bytes in sparse indices, rANS words and block tails are not required to be zero.
validateskips the header checks when buffers are not on the host. The CUDA follow-up must validate beforeblock_tree_sliceruns on copied data.
Smaller notes:
scalar_atand the spine walk trustleft_subtree_bytes. On a corrupt file they can return wrong values whereexecutereturns an error, but nothing panics.- The root-only compare path in
spine.rscan leave set bits pastlenin the last byte.BitBufferprobably masks them, but I did not check this. - The NEON code is gated on
target_arch = "aarch64", nottarget_feature = "neon". - No test proves that compare, filter or take used the pushdown and did not fall back. Compare has no test at
block_shift13, with values at or above 2^32, or with the constant on the left.
Proportion: 12.6k lines is large for an experimental encoding, though about 2.9k are tests and benchmarks. These parts could land later: the encoder-only SIMD (partition_ranks_*, pack_flat_codes_*, about 470 lines) and the SSSE3/SSE4.1 tier, which CI never runs on AVX2 runners. estimate_compressed_bits could also move to #12104, its only caller. The NEON 64-byte merge bodies in neon.rs are duplicated. The decode kernels and the core codec look proportionate.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Merging this PR will not alter performanceWarning vortex-data has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed. 2 warnings
Performance Changes
Comparing Footnotes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf5f738847
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed the review notes in
|
roborev: Combined Review (
|
robert3005
left a comment
There was a problem hiding this comment.
I read the decode path, the SIMD merge and unpack kernels, the rANS decoder, the plugin and the take/filter/compare kernels at 1878d3b6. I found no new correctness or soundness bug. The in-place merges now are unsafe fn with a stated precondition and length asserts, and the SIMD loads stay inside the checked lengths. Take falls back when indices.len() does not fit in u32, so the u32 cursors cannot wrap. I do not repeat the points that the earlier reviews already raised.
The main problem is size. The PR adds about 13k lines in one change. The repo guidance asks for changes under about 500 lines, and a new wire format needs a careful line-by-line review. At this size, that review is not practical. Please split it. A possible order:
- Scalar codec only:
pow2_bin,tree,bitmap_rans, scalarencode/decode,array,plugin, the edition entry, and the wire-contract tests. This PR fixes the wire format, so it gets the most careful review. - SIMD decode kernels (
simd/neon.rs,simd/x86.rs, and the dispatch insimd/mod.rs), with tests that compare each tier to the scalar path. - Compute pushdown:
codec/spine.rsandcompute.rs(compare, filter, take, ZigZag). - Encoder-only SIMD and the benchmark.
Each step keeps the wire format unchanged, so the later PRs need no format review.
Test volume: tests.rs has 28 test functions with 72 #[case] entries, and conformance_tests.rs adds 7 more with 8 cases. That is far above the 20-case guideline, and no test uses hegeltest. Most of the matrices check the same few properties on different inputs. A small number of hegeltest properties would cover more inputs with less code: round trip equals the input; compare, filter and take equal the canonical result; a slice round trips; and random byte changes in any buffer give an error or a value, never a panic.
robert3005
left a comment
There was a problem hiding this comment.
The golden metadata test and the export changes resolve those two points. Two points from my earlier review are still open and have no reply: the split into smaller PRs (the PR is still about 13.2k lines), and the test volume (tests.rs still has 29 tests with 72 #[case] entries and no hegeltest property). Please reply on these before the next round.
|
Thanks for flagging the two open points — holding off on splitting #12103 into smaller PRs and rewriting |
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
I reviewed 71191e4 with fresh eyes, focusing on the unsafe SIMD merges, slice boundaries, nulls and validation of untrusted input. I found no correctness bugs. Every SIMD store and load is bounded, the in-place merges never write past unread bytes, from_bytes and validate_block_headers reject malformed trees and offsets, and with_buffers re-runs validation. vortex.pivco is in UNSTABLE only, and the default core session rejects writing it. Nits:
scratch_as_init(bitmap_rans.rs:834) is a safepub(crate) fnthat turns&[MaybeUninit<u8>]into&[u8]. It is sound only when the caller passes the scratch buffer thatNodeBitmap::readfilled.bit_and_ranks,rank1_and_count1andinto_densecarry the same unchecked contract. All current callers are correct, but making theseunsafe fnwith a# Safetysection would match the repo's conventions.plugin.rs:98reads a metadatablock_shiftof 0 as 12, but the writer always writes the real value. That gives the same array two valid wire forms. While the encoding is in UNSTABLE, rejecting 0 is cheap.bitmap_rans.rs:504could usevortex_ensure_eq!instead ofvortex_ensure!(word_pos == words.len(), ...).
|
Addressed all three nits in
|
lwwmanning
left a comment
There was a problem hiding this comment.
Review by Gemini 4 Carbon on behalf of @lwwmanning.
vortex.pivco addresses a real gap for skewed/heavy-tailed integer columns, but at +12,973 lines across 30 files—combining a new wire format, rANS codec, 3,029 lines of unsafe x86/NEON intrinsics, spine-walking compute pushdown, and 2,903 lines / ~104 hand-rolled unit tests with zero hegeltest properties—this is ~25x AGENTS.md's size target and still has @robert3005's split requests open. There are also two wire-format leaks in PivcoMetadata that should be cleaned up before landing even in UNSTABLE:
- Split into a reviewable 4-PR stack:
- PR 1 — Core scalar codec,
PivcoArray,PivcoPlugin, andUNSTABLEwire registration:pow2_bin.rs,tree.rs,bitmap_rans.rs, scalarcodec/{mod,encode,decode}.rs(withsimdstubbed to scalar fallbacks),array.rs,plugin.rs,lib.rs,vortex-edition/vortex-file/vortexwiring, golden metadata, wire validation tests, and Hegel roundtrip tests (~2.5k LOC, zerounsafeSIMD). - PR 2 — SIMD decode kernels:
simd/{mod,neon,x86}.rsdecode merges & flat unpacks, tested directly for bit-exact parity against PR 1's scalar decoder. Deduplicate the repeated 64-byte merge loop bodies insimd/neon.rsvia an#[inline(always)]helper/macro, and drop the intermediateSSSE3andSSE4.1tiers insimd/x86.rsunless a target host requires them (keepingAVX2+ scalar removes ~700 lines ofunsafeintrinsics shadowed on AVX2 CI). - PR 3 — Compute pushdown kernels:
codec/spine.rsandcompute.rs(compare,filter,take,slice, and fusedZigZag(Pivco)), verified via Hegelcheck_encoding_roundtrip_and_ops. - PR 4 — Encoder SIMD + CodSpeed benchmarks:
partition_ranks_*/pack_flat_codes_*andencodings/pivco/benches/pivco_compress.rs+scripts/codspeed_bench_counts.json.
- PR 1 — Core scalar codec,
- Clean up
PivcoMetadatawire contract before PR 1 lands (encodings/pivco/src/array.rs&plugin.rs):- Remove in-memory slice offsets from wire
PivcoMetadata:tree_base_offset(proto tag4) andraw_base_word_offset(proto tag5) only exist for zero-copy in-memoryslice().host_trim(array.rs) already rebases block headers to0and trimstree_payloadandraw_bits. Callinghost_triminsidePivcoPlugin::serializeremoves two permanent protobuf fields and avoids serializing dead prefix bytes from sliced parent buffers. - Single canonical wire form for
len == 0:PivcoPlugin::deserialize(plugin.rs:122) accepts bothtree_bytes = []and[OP_LEAF, 0]. Enforce a single canonical representation ([OP_LEAF, 0], matchingencode_with_options) forlen == 0.
- Remove in-memory slice offsets from wire
- Replace the 2,903-line / ~104-case unit-test matrix with
hegeltest+<= 20focused unit tests (AGENTS.md):encodings/pivco/src/tests.rs(2,179 lines, 87 cases) andconformance_tests.rs(466 lines, ~14 cases) manually cross-product dtypes × modes × block shifts × nullability withouthegeltest, andvortex/src/editions/tests.rsadds a 258-line query kitchen sink where other encodings test edition gating in ~25 lines.
Remediation Plan
- Tighten
PivcoMetadatainencodings/pivco/src/array.rs&encodings/pivco/src/plugin.rs:- Keep
tree_base_offsetandraw_base_word_offsetstrictly as in-memory fields onPivcoData, drop tags4and5fromPivcoMetadata, callhost_trim()inPivcoPlugin::serializewhen sliced, remove the emptytree_bytesspecial case forlen == 0indeserialize, and regenerate the golden metadata test bytes.
- Keep
- Replace repetitive unit matrices with 3
#[hegel::test]properties +<= 20focused unit tests:- Add
vortex-array = { workspace = true, features = ["_test-harness-hegel"] }toencodings/pivco/Cargo.toml[dev-dependencies]and add Hegel properties covering: (a) arbitrary primitive integers (u8..=u64,i8..=i64, nullable/non-nullable,0/ sub-block / multi-block / constant / 2-symbol / heavy-tailed) ×(PivcoMode, block_shift in 10..=13)throughcheck_encoding_roundtrip_and_ops; (b) fusedZigZag(Pivco)compare/filter/takevs canonical; and (c) arbitrary byte-mutation of serializedmetadata/tree_payload/raw_bitsassertingOkorVortexErrorwithout panics/UB. - Trim
tests.rs+conformance_tests.rsto<= 20targeted invariant/wire-guard/SIMD-tier-parity tests, and shrinkunstable_pivco_vortex_file_roundtrip_and_queriesinvortex/src/editions/tests.rsto ~25–30 lines checkingUNSTABLEwrite/read vs frozenCORErejection.
- Add
- Carve into the 4-PR stack above (and strip the
<!-- devin-review-badge-begin -->HTML block from the PR descriptions).
|
Thanks for the review. Keeping #12103 whole and leaving |
Adds the core scalar vortex-pivco crate, PivcoArray, PivcoPlugin wire contract (with host_trim rebasing and canonical empty tree [TAG_LEAF, 0]), UNSTABLE edition registration, Hegel roundtrip/wire-fuzz properties, and focused wire-guard unit tests. Co-Authored-By: Antigravity <noreply@google.com> Signed-off-by: Will Manning <will@willmanning.io>
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
I checked the two new commits. They only add CompareMode::TOTAL_ORDER to compare calls in tests and benches, which is right for integers, so the format is unchanged. Two corrections to the metadata points in the last review, before anyone acts on them:
- There is no
host_trimin the crate. The host branch ofPivcoData::slice(array.rs lines 678 to 727) already trimstree_payloadandraw_bits, so a host-sliced array writes no dead prefix bytes. It keeps absolute offsets in the block headers, which is whytree_base_offsetis non-zero. To drop tags 4 and 5,serializewould have to rewrite every block header. - An empty array has more wire forms than the two that review named. An empty
slice(array.rs lines 652 to 664) keeps the parent'sblock_shiftandtree_bytes, and an empty encode keeps the caller'sblock_shift. For example,encode(4096 skewed u32 values).slice(0..0)writeslen = 0with a multi-node tree. Ifdeserializeaccepted only[OP_LEAF, 0]forlen == 0, that array would no longer round trip. If we want one form, the writer should produce it first, for exampleblock_shift = 12andPivcoTree::single_symbol(0), and the reader should then reject the others.
88d0377 to
e218466
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e218466374
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let last_block_start = (expected_blocks - 1) * block_values; | ||
| vortex_ensure!( | ||
| last_block_start < total_end | ||
| && total_end <= last_block_start + usize::from(self.last_block_len), |
There was a problem hiding this comment.
Use checked arithmetic for the final-block bound
When malformed input supplies len == usize::MAX, offset == 0, and last_block_len == block_values, the earlier checked offset + len succeeds, but this expression computes usize::MAX + 1. It therefore panics in overflow-checked builds instead of returning a VortexResult and wraps in release builds; use checked arithmetic or a subtraction-based bound comparison for this final validation.
AGENTS.md reference: AGENTS.md:L199-L200
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 716faeb31: switched total_end to checked_add and changed the final-block check to total_end - last_block_start <= usize::from(self.last_block_len) (with test_deserialize_rejects_usize_max_len_without_overflow covering len == usize::MAX).
| let needed_tree_len = (prev.tree_byte_offset - tree_base_offset) as usize; | ||
| vortex_ensure!( | ||
| needed_tree_len <= tree_payload_len, | ||
| "Pivco hdr[B].tree_byte_offset - tree_base_offset ({needed_tree_len}) exceeds tree_payload length ({tree_payload_len})" | ||
| ); | ||
|
|
||
| if has_extra_bits { | ||
| let needed_raw_words = (prev.raw_word_offset - raw_base_word_offset) as usize; | ||
| let needed_raw_bytes = needed_raw_words | ||
| .checked_mul(8) | ||
| .ok_or_else(|| vortex_err!("Pivco raw_bits byte length overflow"))?; | ||
| vortex_ensure!( | ||
| needed_raw_bytes <= raw_bits_len, | ||
| "Pivco (hdr[B].raw_word_offset - raw_base_word_offset) * 8 ({needed_raw_bytes}) exceeds raw_bits length ({raw_bits_len})" | ||
| ); | ||
| } |
There was a problem hiding this comment.
Low: PivcoPlugin::deserialize accepts non-canonical layouts for non-empty arrays, which goes against the wire-contracts rule "require any stored length to match exactly". validate_block_headers only checks lower bounds. So it accepts a non-zero hdr[0].tree_byte_offset/raw_word_offset (a hidden base offset) and trailing bytes after hdr[B] in tree_payload/raw_bits. Since vortex.pivco is in an unstable edition, readers or writers could come to depend on these forms before the format is frozen.
Fix: For len > 0, have deserialize require zero offsets in hdr[0] and exact hdr[B] matches with tree_payload.len() and, when has_extra_bits, raw_bits.len() / 8. Keep the lower-bound checks in validate_block_headers for in-memory windows, and add corruption test cases for both forms.
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
This rewrite changes the wire format after its last manual review. PivcoMetadata drops tags 4 and 5 and moves tree_bytes to tag 4 and has_validity to tag 5. The goldenfile shrinks from 20 bytes to 16 bytes. The rewrite keeps the array ID, the rANS table pins and the pinned block bytes. The new format needs another manual review before this merges.
I traced host_trim in serialize, and it is correct. It rebases every block header to zero, trims both payload buffers, and validates the result again.
Two things:
-
An empty array still has four wire forms.
host_trimkeeps the array'sblock_shiftwhenlen == 0, anddeserializeaccepts any shift from 10 to 13 there. For example, encoding an empty array with shift 10 and with shift 13 writes different metadata. Please writeblock_shift = 12for empty arrays and reject other shifts on read. -
The conformance suites no longer run anywhere in the stack. The deleted
conformance_tests.rsran the consistency, cast, binary numeric and search sorted suites. The Hegel harness does not cover those four. The two other encodings on develop that use the harness also runtest_array_consistency. Please add one rstest here that runs the consistency and cast suites over a few encoded arrays. Include nullable, non-nullable and multi-block inputs.
…nformance rstest Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Addressed both in
Also fixed Codex's P1 final-block bound overflow ( |
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
Adds
vortex-pivco, an experimental wavelet-tree integer encoding (vortex.pivco) for skewed integer columns that supports fast scans and point lookups without giving up entropy compression. Each block stores power-of-two bin symbols in a Huffman or order-preserving wavelet tree paired with raw low bits, keeping slice base offsets strictly in-memory by trimming and rebasing on serialize and enforcing a single canonical empty-tree encoding.Wire format change: registers
vortex.pivcoin theunstable2026.10.0edition with a goldenfile for its metadata; frozen editions such ascorecontinue to reject it. Follow-up PRs add NEON/AVX2 decode SIMD, compute pushdowns, encoder SIMD/benchmarks, andPivcoSchemeintegration.Authored with AI assistance.