perf(array): stop flattening appended list views in ListViewBuilder [builders-child-stack] - #9046
Open
claude[bot] wants to merge 1 commit into
Open
perf(array): stop flattening appended list views in ListViewBuilder [builders-child-stack]#9046claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
Merging this PR will improve performance by 95.8%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
robert3005
force-pushed
the
claude/listview-builder-keep-overlaps-9ze0t6
branch
from
July 29, 2026 07:31
bdb1acd to
5343548
Compare
This was referenced Jul 29, 2026
Closed
Open
`append_listview_array` rebuilt every incoming `ListViewArray` into an exact layout before appending it. Rebasing offsets by the number of elements already in the builder is correct whatever layout they have, so the rebuild bought nothing except an unconditional promise that the finished array is zero-copyable to a `ListArray` - and it cost the caller any sharing the source expressed. A constant list array is the case that matters: canonicalizing one already points every view at a single copy of the value, and flattening it materialized one copy per row. Appending a 10,000-row constant list of three elements produced 30,000 elements; it now produces 3. Keep trimming unreferenced elements, but otherwise append the views as they arrived and track whether the result is still zero-copyable to a `ListArray` instead of asserting it. The flag is per-array and consumers already branch on it, so callers that need an exact layout can rebuild. Signed-off-by: Claude <noreply@anthropic.com> Signed-off-by: Robert Kruszewski <robert@spiraldb.com>
robert3005
force-pushed
the
claude/listview-builder-keep-overlaps-9ze0t6
branch
from
July 29, 2026 13:48
5343548 to
0779ba5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
New bottom of the
builders-child-stack. This is the change that makes the rest of the stack pay off, so it lands first.ListViewBuilder::append_listview_arrayrebuilt every incomingListViewArrayinto an exact layout before appending it:Rebasing every offset by the number of elements already in the builder is correct whatever layout the source has, so that rebuild bought nothing but an unconditional promise that the finished array is zero-copyable to a
ListArray. What it cost was any sharing the source had gone to the trouble of expressing, sinceMakeExactis documented as "removing all data overlaps and creating a flattened layout".The case that matters is a constant list array.
constant_canonical_list_arrayalready does the clever thing — "canonicalize only applies to the top level array, so we can simply have 1 scalar in our childelementsand have all list views point to that scalar" — and the builder immediately undid it. Measured on a 10,000-row fill of a 3-element list:That unblocks callers replacing per-row append loops with a single array append —
encodings/sparse'sappend_list_fillcallsappend_array_as_list(fill_elements, ctx)once per filled row, which for a sparse list array of a million rows is a million copies of the same handful of values.What changes are included in this PR?
append_listview_arraykeeps trimming unreferenced elements —ListViewRebuildMode::TrimElementspreserves overlap and the existing flag — but otherwise appends the views as they arrived.ListViewBuildergains azero_copy_to_listfield that startstrueand is cleared when an appendedListViewArraybrings a layout the builder chose not to rewrite.finish_into_listviewreports it instead of hardcodingtrue. Every other append lays its lists down back to back, so only this one path can clear it.The test is deliberately conservative: the result stays zero-copyable only if the incoming views are packed back to back and reference every element they carry, since the next append starts where this one's elements end. Leading or trailing unreferenced elements would leave a gap in the middle of the combined array.
What APIs are changed? Are there any user-facing changes?
No signature changes. Two behavioural ones, both intentional:
ListViewArraynow finishes non-zero-copy-to-list. The flag is per-array and consumers already branch on it (vortex-duckdb/src/exporter/list_view.rs:59has both paths); callers who need an exact layout canrebuild.test_extend_from_array_overlapping_listviewis updated to assert the new contract, including that a null list keeps its source size metadata rather than being rewritten to zero.TrimElementsonly drops leading and trailing ones.uncompressed_size_in_bytes::list_matches_materialized_sizeused a builder round-trip as its proxy for "materialized" and relied on that compaction, so it now compares against an explicitlyMakeExact-rebuilt array; the comment explains why.Checks
cargo test -p vortex-array— 3138 lib tests, including a new one asserting a 10,000-row constant list append stores its value oncecargo test --lib --testsgreen forvortex-arrow,vortex-layout,vortex-scan,vortex-file,vortex-datafusion,vortex-btrblocks,vortex-compressor,vortex-row,vortex,vortex-ipc,vortex-sparse,vortex-fastlanescargo +nightly fmt --all,cargo clippy -p vortex-array --all-targets --all-features,typosGenerated by Claude Code
Stacked PR Chain: builders-child-stack