refactor(array): canonicalize chunked structs and FSLs through the builder [builders-child-stack]#8967
Conversation
Merging this PR will degrade performance by 30.96%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
…ilder `pack_struct_chunks` and `swizzle_fixed_size_list_chunks` existed because `append_to_builder` used to decode a builder's children: without them, canonicalizing a `ChunkedArray` would concatenate every chunk's children instead of reusing them. Their doc comments describe what the builders now do on their own, so both are dead weight. Route both dtypes through the generic builder path, telling it to keep every chunk boundary. `ListArray` keeps its swizzle for now — that one also allocates its offsets and sizes through the session allocator, which the builders cannot yet do. Signed-off-by: Claude <noreply@anthropic.com>
dc71bbf to
85f8dcd
Compare
5dd13d4 to
afed52f
Compare
Rationale for this change
Stacked on #8966 → #8965 → #8964 — review those first. This is the payoff for the three below it.
ChunkedArray's_canonicalizecarried four hand-written special cases plus a genericappend_to_builderfallback. Two of them existed purely becauseappend_to_builderused to decode a builder's children; their doc comments say so:pack_struct_chunks— "a singleStructArray, where the data for each field is aChunkedArray"swizzle_fixed_size_list_chunks— "reuse the chunks'elementschildren directly as the chunks of a combinedelementsarray without copying"That is what
ChildBuilderdoes now, so both are dead weight — an extra path to keep correct for a result the generic path already produces.What changes are included in this PR?
DType::StructandDType::FixedSizeListfall through to the builder, which is toldset_min_chunk_len(0): every chunk is worth keeping however short, since reusing the chunks' children is the entire point of canonicalizing aChunkedArrayrather than concatenating it. Both helpers are deleted (57 insertions, 60 deletions, one file).I verified the shapes match before deleting anything. A
tree_displayprobe over chunked struct / list / FSL inputs produces byte-identical trees on both paths for chunks of 200 rows — struct field isvortex.chunked(i32, len=400)with two chunks, FSLelementslikewise. Two newrstestcases lock that in using chunks of one row, far below the threshold a nested builder applies on its own; dropping theset_min_chunk_len(0)line fails both.What is not included
ListArraykeepsswizzle_list_chunks. The builder produces the same shape —is_zero_copy_to_list: trueand all — but the swizzle also allocates its offsets and sizes throughctx.allocator(), and builders are not allocator-aware:builder_with_capacity_intakes aHostAllocatorRefand discards it (let _allocator = allocator;).list_canonicalize_uses_memory_session_allocatorcatches exactly this. Making it work means threading an allocator throughBufferMutinvortex-buffer, which has none today — a bigger and separate piece of work than this stack, so the list swizzle stays until someone does it.pack_variant_chunksstays too:builder_with_capacityisunimplemented!()forDType::Variant.StructArray::try_concatis now unused in-tree. It ispub, and a useful helper in its own right, so I left it — removing public API seemed like a separate call for a reviewer to make rather than something to slip into this PR.What APIs are changed? Are there any user-facing changes?
No API changes. The observable difference is confined to chunked arrays with chunks shorter than 64 rows, and there is none:
set_min_chunk_len(0)reproduces the swizzles' behaviour of preserving every boundary.Checks
cargo test -p vortex-array— 3177 lib testscargo test --lib --testsgreen forvortex-arrow,vortex-layout,vortex-scan,vortex-file,vortex-datafusion,vortex-btrblocks,vortex-compressor,vortex-row,vortex,vortex-ipc,vortex-json,vortex-tensorcargo +nightly fmt --all,cargo clippy -p vortex-array --all-targets --all-featuresGenerated by Claude Code
Stacked PR Chain: builders-child-stack
Generated by Claude Code