Skip to content

perf(arrow/array): bulk append fixed-width empty values - #1180

Merged
zeroshade merged 1 commit into
apache:mainfrom
fallintoplace:perf/arrow-fixed-width-empty-values
Aug 14, 2026
Merged

perf(arrow/array): bulk append fixed-width empty values#1180
zeroshade merged 1 commit into
apache:mainfrom
fallintoplace:perf/arrow-fixed-width-empty-values

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

What changed

AppendEmptyValues used to call AppendEmptyValue in a loop. For larger batches, each value repeated the reserve, bitmap, and storage work.

This change makes fixed-width empty appends bulk operations:

  • reserve space once
  • zero the appended value range in one operation
  • set validity bits in bulk
  • clear boolean value bits separately from the validity bitmap
  • keep the existing single-value path for count 1

The numeric generated source and template are updated together. The covered builders are numeric, temporal, interval, float16, decimal, fixed-size binary, and boolean.

Correctness

  • Empty values stay valid, including when the builder reuses storage.
  • Reused numeric and boolean storage is explicitly tested.
  • bufferBuilder.Advance now zeroes skipped bytes as documented.
  • BooleanBuilder.Resize now preserves the requested logical length when truncating.
  • Zero and negative counts remain no-ops.

Benchmark

AppendEmptyValues(1024) on an Apple M1 Pro. Three runs were used for each result.

Builder Before After Allocs
Int32 5.15 us 1.50 us 11 -> 5
Int64 6.44 us 2.52 us 11 -> 5
Timestamp 6.50 us 3.22 us 12 -> 6
Boolean 4.04 us 0.30 us 7 -> 5
Fixed-size binary 10.1 us 5.69 us 16 -> 7

Small counts keep the single-value path, so the biggest improvement is for larger batches.

Tests

  • go test ./arrow/array
  • go vet ./arrow/array
  • Added focused correctness tests and representative benchmarks

@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 bulk path ordering is correct (Reserve → zero range → unsafeSetValid), and both drive-by fixes — Advance zeroing per its documented contract and the BooleanBuilder.Resize truncation length — are genuine correctness improvements with test coverage. Benchmarks look convincing.

May need a rebase now that #1185 touched builder.go.


This review was drafted with the help of an AI-assisted tool and may contain mistakes; it was reviewed and confirmed by an Apache Arrow maintainer before posting. See the contributing guide for what the project considers a maintainer review.

zeroshade pushed a commit that referenced this pull request Aug 14, 2026
…#1183)

## What does this PR do?

- reserves fixed-size list parent slots once in `AppendNulls` and
`AppendEmptyValues`
- updates the parent validity bitmap in bulk
- appends all child null or empty values with one bulk builder call

The child append count is `listSize * n`, so the parent and child
lengths stay in sync.

## Why?

Both methods currently loop over every parent value. Each parent append
also loops over every child value.

This removes the parent loop and lets child builders use their bulk
append paths. The change is independent, but it also composes with #1173
and #1180.

## Benchmarks

Apple M1 Pro, 65,536 `FixedSizeList<Int32>` rows, `GOMAXPROCS=1`.

Standalone on `main`:

| list width | nulls before | nulls after | change | empty before |
empty after | change |
| ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| 4 | 1.10 ms | 0.86 ms | -22% | 1.55 ms | 1.07 ms | -31% |
| 16 | 3.76 ms | 2.74 ms | -27% | 5.43 ms | 3.90 ms | -28% |
| 64 | 13.03 ms | 11.07 ms | -15% | 19.35 ms | 14.86 ms | -23% |

With #1173 and #1180 applied underneath:

| list width | nulls before | nulls after | change | empty before |
empty after | change |
| ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| 4 | 1.56 ms | 0.18 ms | -88% | 2.01 ms | 0.20 ms | -90% |
| 16 | 4.69 ms | 0.33 ms | -93% | 6.89 ms | 0.42 ms | -94% |
| 64 | 16.27 ms | 0.74 ms | -95% | 22.18 ms | 0.92 ms | -96% |

```text
GOMAXPROCS=1 go test ./arrow/array -run '^$' -bench '^BenchmarkFixedSizeListBuilderBulkAppend$/(nulls|empty)/rows=65536/width=(4|16|64)$' -benchmem -benchtime=300ms -count=5
```

## Tests

- added coverage for unaligned parent validity bits
- verifies parent validity and null counts
- verifies child length, null slots, and zero-valued empty slots
- ran `go test ./arrow/...`
- ran `go test -race ./arrow/array`
- ran `go vet ./arrow/array`
@fallintoplace
fallintoplace force-pushed the perf/arrow-fixed-width-empty-values branch from ef7dbb0 to e3418c8 Compare August 14, 2026 16:54
@zeroshade
zeroshade merged commit 726d10b into apache:main Aug 14, 2026
26 of 27 checks passed
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