Skip to content

Add experimental PIVCO wavelet-tree integer encoding in UNSTABLE - #12103

Open
lwwmanning wants to merge 6 commits into
developfrom
wm/pivco-array
Open

lwwmanning wants to merge 6 commits into
developfrom
wm/pivco-array

Conversation

@lwwmanning

Copy link
Copy Markdown
Contributor

Between fast BitPacked/FoR and slow archival Pco (VortexCompact), Vortex lacks an integer entropy encoding that keeps fast SIMD scans, sub-microsecond point lookups, selective filter/take, direct CompareKernel pushdown, and block-parallel GPU decode. Modeled on Marcin Żukowski's pivco-huffman, vortex.pivco splits non-negative integers into Pow2-Bin symbols (0..150) plus an 8-byte-aligned raw_bits stream (composing signed integers via ZigZag), and encodes each independent 2^block_shift (1,024..=8,192) block as a chunk-level wavelet tree (Huffman with collapsed flat subtrees, or OrderPreserving for range pushdown) whose node bitmaps use RAW, ALL_ZERO/ALL_ONE, SPARSE, or 32-lane static Bernoulli byte-rANS.

For reviewers navigating encodings/pivco/src/, dependencies flow strictly bottom-up: pow2_bin, simd (neon and x86), and bitmap_rans sit at the base; tree builds and serializes wavelet trees; codec (encode, decode, spine) handles block compression, L1-resident tail-in-place ping-pong decode, top-down $O(\text{depth})$ scalar_at, and spine-walking predicates; and array, compute, and plugin wire vortex.pivco into the UNSTABLE edition with 4B/2B-aligned tree_payload buffers and zero-sync SliceReduce ready for a follow-up CUDA kernel PR.

On 1M-row skewed and power-law integer distributions, vortex.pivco decodes at 4.5–51.9 GB/s per core (2.8–3.6× faster than 32-lane symbol rANS), evaluates pushed-down comparisons at 30–940 GB/s, and serves scalar_at in ~250 ns.

Authored with AI assistance.

Adds the vortex-pivco crate implementing Pow2-Bin + PIVCO wavelet-tree integer compression (PH, PHA, OP-PHA) with canonical 32-lane static byte-rANS bitmaps, 3-buffer split wire layout, L1-resident in-place ping-pong decoding, x86_64/NEON SIMD kernels, O(depth) top-down scalar_at, zero-sync windowed SliceReduce, Filter/Take/Compare/ZigZag kernels, narrow estimate_compressed_bits cost estimation, strict wire/bounds/dtype-width validation, and full Vortex conformance suites. Registers vortex.pivco in UNSTABLE edition and default file encodings, and adds the pivco_compress benchmark with its CodSpeed shard count.

Signed-off-by: Will Manning <will@willmanning.io>

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Pin the rANS tables in a test for backward compatibility. compute_bernoulli_freqs builds 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.

  2. merge_vec_vec_in_place_left, merge_vec_vec_in_place_right, merge_cst_vec_in_place and merge_vec_cst_in_place in simd/mod.rs are safe functions, but they do not check that right holds popcount(bm, k) bytes. The scalar tail reads r_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 in decode.rs and spine.rs always compute k_right with a popcount, so no file can reach this. Mark them unsafe fn with that precondition, or compute k_right inside 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 == 0 is 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.
  • validate skips the header checks when buffers are not on the host. The CUDA follow-up must validate before block_tree_slice runs on copied data.

Smaller notes:

  • scalar_at and the spine walk trust left_subtree_bytes. On a corrupt file they can return wrong values where execute returns an error, but nothing panics.
  • The root-only compare path in spine.rs can leave set bits past len in the last byte. BitBuffer probably masks them, but I did not check this.
  • The NEON code is gated on target_arch = "aarch64", not target_feature = "neon".
  • No test proves that compare, filter or take used the pushdown and did not fall back. Compare has no test at block_shift 13, 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.

@lwwmanning
lwwmanning marked this pull request as ready for review November 26, 2026 07:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T07:07:24.964562Z bf5f738 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lwwmanning
lwwmanning added this pull request to stack #12105 November 26, 2026 07:04
… and wire/pushdown tests

- Mark in-place SIMD merge helpers as unsafe fn with explicit popcount/length preconditions and safety comments at all call sites
- Gate NEON merge paths on target_feature = "neon" in addition to target_arch = "aarch64"
- Mask trailing padding bits past logical len in the root-only compare fast path
- Add wire-format pinning tests for the 16 static Bernoulli rANS tables and all bitmap markers, plus direct CompareKernel/FilterKernel/TakeExecute pushdown and shift-13/u64/const-left edge-case tests

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@codspeed

codspeed Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 12.82%

Warning

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.

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

❌ 1 regressed benchmark
✅ 2151 untouched benchmarks
🆕 32 new benchmarks
⏩ 164 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation varbinview_large 132.3 µs 151.8 µs -12.82%
🆕 CPU Simulation compare_eq_zero[skewed_gt_u64] N/A 1.2 ms N/A
🆕 CPU Simulation compare_eq_zero[zipf64_u32] N/A 496.6 µs N/A
🆕 CPU Simulation compare_lt[skewed_gt_u64] N/A 1.2 ms N/A
🆕 CPU Simulation compare_lt[zipf64_u32] N/A 864.8 µs N/A
🆕 CPU Simulation decode[signed_zigzag_i32/op_pha] N/A 8.3 ms N/A
🆕 CPU Simulation decode[signed_zigzag_i32/ph] N/A 7.4 ms N/A
🆕 CPU Simulation decode[signed_zigzag_i32/pha] N/A 7.5 ms N/A
🆕 CPU Simulation decode[skewed_gt_u64/op_pha] N/A 3.3 ms N/A
🆕 CPU Simulation decode[skewed_gt_u64/ph] N/A 2.5 ms N/A
🆕 CPU Simulation decode[skewed_gt_u64/pha] N/A 3.3 ms N/A
🆕 CPU Simulation decode[zipf64_u32/op_pha] N/A 7.9 ms N/A
🆕 CPU Simulation decode[zipf64_u32/ph] N/A 7.2 ms N/A
🆕 CPU Simulation decode[zipf64_u32/pha] N/A 7.2 ms N/A
🆕 CPU Simulation encode[signed_zigzag_i32/op_pha] N/A 11.9 ms N/A
🆕 CPU Simulation encode[signed_zigzag_i32/ph] N/A 10.9 ms N/A
🆕 CPU Simulation encode[signed_zigzag_i32/pha] N/A 10.9 ms N/A
🆕 CPU Simulation encode[skewed_gt_u64/op_pha] N/A 7.6 ms N/A
🆕 CPU Simulation encode[skewed_gt_u64/ph] N/A 6.9 ms N/A
🆕 CPU Simulation encode[skewed_gt_u64/pha] N/A 7.6 ms N/A
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing wm/pivco-array (ce37371) with develop (7bfb804)

Open in CodSpeed

Footnotes

  1. 164 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread encodings/pivco/src/plugin.rs Resolved
Comment thread encodings/pivco/src/array.rs Resolved
Comment thread encodings/pivco/Cargo.toml Resolved
Comment thread encodings/pivco/src/codec/decode.rs Resolved
Comment thread Cargo.toml Resolved
…hecks

- Add explicit PivcoMetadata::has_validity flag (tag 7) and ignore trailing extra children on deserialize per wire-contracts.md
- Use checked_add in checked_num_blocks_for during deserialization and array validation to reject offset + len overflow
- Bound left/right subtree frames and validate left_subtree_bytes bounds in decode_symbol_at and prefix_ebits_sum
- Add regression tests for declared validity, ignored trailing children, and offset + len overflow

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed the review notes in 2df784527 and 1878d3b64:

  • Pinned all 16 static Bernoulli byte-rANS frequency tables and serialized block bytes per bitmap marker (RAW, ALL_ZERO, ALL_ONE, SPARSE_ONE, SPARSE_ZERO, STATIC_BYTE_RANS).
  • Marked the four in-place SIMD merge helpers as unsafe fn with explicit popcount/length preconditions and safety comments at all call sites, and gated NEON paths on target_feature = "neon".
  • Masked trailing padding bits past logical len in the root-only compare fast path.
  • Added direct CompareKernel/FilterKernel/TakeExecute pushdown tests and edge-case coverage for block_shift = 13, u64 >= 2^32, constant-on-left comparisons, and non-byte-aligned root-only compare.
  • Added explicit PivcoMetadata::has_validity (tag 7), ignored trailing extra children per wire-contracts.md, checked offset + len overflow via checked_num_blocks_for, and bounded left_subtree_bytes frames in decode_symbol_at / prefix_ebits_sum.

@vortex-roborev-bot

vortex-roborev-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

roborev: Combined Review (ce37371)

Verdict: No issues found.


Reviewers: claude-code | Synthesis: claude-code, 0s | Total: 45s, cost partial ~$0.48

@robert3005 robert3005 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Scalar codec only: pow2_bin, tree, bitmap_rans, scalar encode/decode, array, plugin, the edition entry, and the wire-contract tests. This PR fixes the wire format, so it gets the most careful review.
  2. SIMD decode kernels (simd/neon.rs, simd/x86.rs, and the dispatch in simd/mod.rs), with tests that compare each tier to the scalar path.
  3. Compute pushdown: codec/spine.rs and compute.rs (compare, filter, take, ZigZag).
  4. 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.


/// Serialized protobuf metadata for a [`PivcoArray`].
#[derive(Clone, PartialEq, Eq, prost::Message)]
pub struct PivcoMetadata {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs/specs/versioning/wire-contracts.md asks for a golden file of the metadata bytes, written with check_metadata, with every field set to a value other than its default. I found no check_metadata call in this crate. The pinned block-bytes test covers the buffers, but not this message. Add a check_metadata("pivco.metadata", ...) test with offset, last_block_len, block_shift, both base offsets, tree_bytes and has_validity all set to non-default values. Without it, a change to a tag or a field type does not fail a test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_pivco_metadata_golden with check_metadata("pivco.metadata", ...) and all fields set to non-default values in dae58d112, along with the checked-in encodings/pivco/goldenfiles/pivco.metadata golden file.

Comment thread encodings/pivco/src/lib.rs Outdated
pub use codec::PivcoBlockOffset;
pub use codec::PivcoOptions;
pub use codec::block_header_stride;
pub use codec::estimate_compressed_bits;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crate exports many internals: estimate_compressed_bits, EBITS_TABLE, MAX_SYMS, pow2_sym_and_ebits, PivcoTree (with build, to_bytes, from_bytes), PivcoBlockOffset, block_header_stride, the header-size constants, and the 9-argument PivcoData::try_new. Each export becomes API that later changes must keep. Please keep these pub(crate) unless a caller outside this crate needs them now. Export them in the PR that adds that caller (for example #12104 for estimate_compressed_bits).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tightened these exports in dae58d112: PivcoData::try_new is now pub(crate), and estimate_compressed_bits, EBITS_TABLE, MAX_SYMS, pow2_sym_and_ebits, PivcoTree, PivcoBlockOffset, block_header_stride, MAX_BLOCK_VALUES, BLOCK_HEADER_BYTES_NO_EXTRA, and BLOCK_HEADER_BYTES_WITH_EXTRA are no longer re-exported from vortex-pivco here. Only the estimator helpers actually called by vortex-btrblocks are re-exported in #12104 (c1b19b7fb).

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>

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of c3e1cd2. The roborev PR comment has the full review.

Comment thread encodings/pivco/src/codec/mod.rs Resolved
Comment thread encodings/pivco/src/codec/spine.rs Resolved
Comment thread encodings/pivco/src/codec/mod.rs Resolved
…s-check estimator

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants