Skip to content

GH-35126: [C++] Reuse full plain chunks in ChunkedArray::Slice - #55719

Draft
Aurantium-47 wants to merge 1 commit into
apache:mainfrom
Aurantium-47:fix/chunked-array-full-slice-35126
Draft

Aurantium-47 wants to merge 1 commit into
apache:mainfrom
Aurantium-47:fix/chunked-array-full-slice-35126

Conversation

@Aurantium-47

Copy link
Copy Markdown

Rationale for this change

Addresses #35126. Repeatedly slicing a table with many chunks recreates Array and ArrayData wrappers for chunks that are included in full. Reusing those wrappers reduces this overhead for full aligned plain chunks; their payload buffers were already zero-copy.

What changes are included in this PR?

In ChunkedArray::Slice, reuse the existing Array wrapper when a chunk is included in full at an aligned boundary, has no statistics, child data or dictionary, and is not an extension array. Boundary chunks, statistics-bearing chunks, nested arrays, dictionary arrays and extension arrays retain the previous slicing path.

Add regression tests for wrapper reuse across aligned plain chunks (including an empty chunk and a chunk with a nonzero logical offset), partial boundary values, and dropping statistics through the existing path.

Are these changes tested?

Prior local validation used this exact patch at upstream main cba325ed67235fe16c307b9cf974a54433d9f9c7:

  • Native arrow-table-test linked to the locally built libarrow.so.2700: 213/213 passed, including 16/16 TestChunkedArray.
  • An exact-method native benchmark using a common Arrow 27.0.0-SNAPSHOT library measured median time from 0.869 s to 0.114 s for a synthetic repeated shrinking-tail workload with 1,000 chunks × 1,024 rows × 10 columns. 692 slice comparisons and additional guard/lifetime checks passed. These timings describe that synthetic workload only.

Submission checks also passed: git apply --check, git diff --check, exact changed-file scope, and byte-for-byte agreement between the applied diff and the verified patch (SHA-256 f22fe8d566c73b9c587587c145629b85a38c39ad9e9ef1033ba8cf34bf5c1151). Current upstream main still matches the tested commit. The native tests and benchmark were completed before this submission; they were not rerun during submission.

Are there any user-facing changes?

Full aligned plain chunks now preserve Array and ArrayData pointer identity with the input instead of creating new wrappers. Keeping the slice alive can therefore extend the lifetime of the original Array and ArrayData wrappers, and their metadata objects are shared. Payload buffers were already shared by the previous zero-copy path. The guarded cases listed above retain their previous behavior.

Was AI used for this PR?

ChatGPT assisted the implementation and local testing. Codex prepared this PR description and submitted this draft.

Reuse existing Array wrappers for complete aligned plain chunks.
Retain the slicing path for boundaries, statistics, nested data,
dictionaries and extension arrays.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant