Skip to content

fix: avoid BinaryViewBuilder ReserveData(0) allocating a block#895

Open
fallintoplace wants to merge 1 commit into
apache:mainfrom
fallintoplace:fix-binaryview-reservedata-zero
Open

fix: avoid BinaryViewBuilder ReserveData(0) allocating a block#895
fallintoplace wants to merge 1 commit into
apache:mainfrom
fallintoplace:fix-binaryview-reservedata-zero

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Problem

BinaryViewBuilder.ReserveData(length) always delegates to multiBufferBuilder.Reserve(length). In practice, Reserve(0) can still create a full default block in the current implementation, which triggers an unnecessary allocation for batches that keep all-view data inlined.

Change

  • Early-return from BinaryViewBuilder.ReserveData when length == 0.
  • Skip calling into blockBuilder.Reserve(0) for that path.
  • Add a regression test with a no-allocation allocator to assert that reserving zero data length does not allocate a view-data block.

Impact

  • Removes unintended memory churn (roughly a full block, e.g., 32 KiB) for the zero-length reservation case.
  • Improves performance for all-inline view builders in small/empty-batch heavy workloads.
  • No behavior change for non-zero ReserveData calls.

Testing

  • Added regression test in this PR covering zero-length ReserveData allocation behavior.
  • Local test run not performed in this PR (test is narrowly scoped and covered by the new assertion).

@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 zeroshade force-pushed the fix-binaryview-reservedata-zero branch from ecb3281 to 2c4b9b4 Compare July 4, 2026 17:08
@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.

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