Skip to content

fix(arrow/array): avoid allocating for ReserveData(0)#895

Open
fallintoplace wants to merge 2 commits into
apache:mainfrom
fallintoplace:fix-binaryview-reservedata-zero
Open

fix(arrow/array): avoid allocating for ReserveData(0)#895
fallintoplace wants to merge 2 commits into
apache:mainfrom
fallintoplace:fix-binaryview-reservedata-zero

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

BinaryViewBuilder.ReserveData always delegated to the block builder. ReserveData(0) could therefore create a full default data block even when every value remains inline.

What changes are included in this PR?

  • Return after the existing size validation when the requested data length is zero.
  • Preserve the normal reserve path for positive lengths.
  • Update integration JSON expectations because an unused empty variadic data buffer is no longer created.

Are these changes tested?

Yes. A no-allocation allocator verifies that ReserveData(0) does not allocate. The array and arrjson packages pass normal and race tests.

Are there any user-facing changes?

Zero-length reservations no longer allocate an unused data block. Positive reservations and the public API are unchanged.

@fallintoplace
fallintoplace requested a review from zeroshade as a code owner July 4, 2026 00:30

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ReserveData(0) short-circuit is reasonable, but the branch doesn't compile on its own:

arrow/array/binary_test.go:705:28: undefined: binaryViewNoAllocAllocator
FAIL	github.com/apache/arrow-go/v18/arrow/array [build failed]

binaryViewNoAllocAllocator is introduced in #888 — it's not on main and not in this PR. Please rebase this on top of #888 (so the helper exists) or add the helper here. Once it builds, the guard + test look good.

Verified by checking out the PR head and running go test ./arrow/array/.

@zeroshade

Copy link
Copy Markdown
Member

Rebased onto main now that #888 has merged (it introduced checkBinaryViewValueSize and the binaryViewNoAllocAllocator test helper). Resolved the ReserveData and binary_test.go conflicts, and confirmed go build/go test ./arrow/array/ are green (both TestBinaryViewBuilderReserveData0DoesNotAllocate and the oversized-value guard pass). This should now compile — over to CI.

@fallintoplace fallintoplace changed the title fix: avoid BinaryViewBuilder ReserveData(0) allocating a block fix(arrow/array): avoid allocating for ReserveData(0) Jul 17, 2026
@fallintoplace
fallintoplace force-pushed the fix-binaryview-reservedata-zero branch from 4b25336 to 7241331 Compare July 17, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants