Chunk-local PatchedArray - #9758
Conversation
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Merging this PR will improve performance by 14.49%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | WallTime | arrow_checked_add_u32_avx2[16384] |
21.4 µs | 17.6 µs | +21.49% |
| ⚡ | Simulation | decompress[u64, (4000, 1024)] |
85.7 µs | 70.7 µs | +21.27% |
| ⚡ | Simulation | allocate_drop_arrow[0] |
456.9 ns | 402.7 ns | +13.45% |
| ⚡ | Simulation | compact_sliced[(1024, 90)] |
1.5 µs | 1.4 µs | +12.03% |
| ⚡ | Simulation | allocate_drop_bytes[0] |
520.2 ns | 466 ns | +11.62% |
| ⚡ | Simulation | compact_sliced[(2048, 90)] |
1.6 µs | 1.4 µs | +11.53% |
| ⚡ | WallTime | mul_u32_nonnull_avx512 |
6.3 µs | 5.7 µs | +10.63% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing mk/patched-chunk-local (66f93b0) with develop (dab1684)
Footnotes
-
206 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. ↩
PatchedArray
Summary
Moves the experimental
Patchedencoding onto the chunk-local layout from #9611 and gives it a new wire ID,vortex.patched_v2. This is the first step of the plan in #7818 to replace the interiorPatcheshelper in BitPacked, ALP, ALP-RD and Sparse with one patch array.One in-memory type, two wire IDs.
Patchedkeeps its name and in-memory ID. The chunk-local layout is written undervortex.patched_v2; the lane-transposed layout of RFC 0027 stays readable undervortex.patchedand is re-sorted into chunk order on load, so no other code path sees lanes. Perdocs/specs/editions.md, a form an old reader does not understand needs a new ID, and CI wrote lane arrays underVORTEX_EXPERIMENTAL_PATCHED_ARRAY=1before edition enforcement landed in #9660.Layout
Metadata is
n_patchesandoffset(grid position of row zero, below 1024). Children:innerlenpatch_indicesu16non-nullable, strictly increasing within a chunkn_patchespatch_valuesn_patcheschunk_offsetsu32non-nullable prefix counts with a terminator(offset + len).div_ceil(1024) + 1Chunk
cownspatch_indices[chunk_offsets[c]..chunk_offsets[c + 1]]. Lookups select the chunk in constant time and binary search at most 1024 indices.Slicing is zero-copy: the inner is sliced exactly,
chunk_offsetsis sliced by chunk, and the patch children are shared. Patches of the first and last chunk that fall outside the slice stay in the children and are skipped on read.compact()rebases when a self-contained array is wanted. This is what removes v1'soffset_within_chunkbookkeeping: nothing is sliced at element granularity.Changes
arrays/patched/layout.rs:PatchedViewover canonical slices (search,live,for_each), layout validation, and global-to-chunk-local conversion. Joe'sPatchesV2container reshaped as the array's internals.array.rs: new slots and metadata,Patched::try_newwith full validation on canonical children,from_array_and_patchesaccepting any unsigned index width,slice_range,compact.append_to_builder,scalar_at, slice and filter reduce rules, compare against a constant, take (binary search instead of a hash map).plugin.rs:PatchedPluginwritesvortex.patched_v2and reads both IDs.vortex-fileand the btrblocks trace tests register it instead of the bare vtable.testdata/lane_*.bin: three lane-layout arrays serialized by the pre-change code ondevelop, including one whose lane order reverses row order and one sliced mid-chunk with a dead patch. Regenerate from a pre-change checkout if they ever need to change.scalar_at, nested slices, compaction), layout validation rejections, serde round trips including a slice with dead patches.Nothing outside
vortex-array/src/arrays/patched/referenced the lane internals. Behaviour underVORTEX_EXPERIMENTAL_PATCHED_ARRAYis unchanged, including the existing problem that enforced editions drop the BitPacking and ALP schemes when it is set; thepatchededition family and the compressor gating are the next PR.Checks run
cargo nextest run -p vortex-array(3458 passed)cargo nextest run -p vortex-fastlanes -p vortex-alp -E 'test(/plugin|patched/)'(8 passed)cargo nextest run -p vortex-btrblocks -E 'test(/trace/)'(6 passed)cargo check -p vortex-compat -p vortex-file --all-targetscargo clippy -p vortex-array -p vortex-file -p vortex-btrblocks --all-targetscargo test --doc -p vortex-array,RUSTDOCFLAGS=-D warnings cargo doc -p vortex-array --no-depscargo +nightly fmt --allNot run: workspace-wide build, GPU crates.