Skip to content

Avoid allocations when slicing owned ArrayData - #11432

Closed
memosmorgan wants to merge 1 commit into
apache:mainfrom
memosmorgan:codex/9140-owned-array-data-slice
Closed

memosmorgan wants to merge 1 commit into
apache:mainfrom
memosmorgan:codex/9140-owned-array-data-slice

Conversation

@memosmorgan

@memosmorgan memosmorgan commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

a

@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-data arrow-array labels Oct 7, 2026
@memosmorgan memosmorgan closed this Oct 7, 2026
@memosmorgan
memosmorgan deleted the codex/9140-owned-array-data-slice branch October 7, 2026 18:37
alamb added a commit to JakeDern/arrow-rs that referenced this pull request Oct 9, 2026
…Data (apache#11433)

# Which issue does this PR close?

- Closes apache#9140

Replaces apache#11432.

# Rationale for this change

Owned `ArrayData` can be sliced without allocating new buffer or child
vectors.

AI assistance: OpenAI Codex generated the implementation and tests, ran
the local checks, and reviewed the diff.

# What changes are included in this PR?

Add `ArrayData::sliced`, which consumes the array and reuses its
allocations, including nested struct children. Use it when converting
owned data to `StructArray`.

# Are these changes tested?

Regression tests cover equivalence with borrowed slicing, offsets,
nested structs, lists, nulls, empty/end slices, and bounds. They also
check that vector allocations are retained.

A local release-mode allocation counter measured the following for
1,024-element inputs sliced at offset 1 for 512 elements, excluding
input construction:

| Data | `slice` allocations | `sliced` allocations |
| --- | ---: | ---: |
| Int32 | 1 | 0 |
| Nested Struct | 3 | 0 |
| List<Int32> | 3 | 0 |

# Are there any significant user-facing changes?

No breaking changes. Borrowed `slice` retains its existing behavior.

Co-authored-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-array arrow-data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant