You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "fallintoplace (via GitHub)" <gi...@apache.org> on 2026/08/27 13:33:17 UTC

[PR] perf(arrow/array): batch-pack boolean values [arrow-go]

fallintoplace opened a new pull request, #1237:
URL: https://github.com/apache/arrow-go/pull/1237

   ## Summary
   
   - Pack BooleanBuilder values into the bitmap one byte at a time.
   - Handle unaligned prefixes and trailing values without changing neighboring bits.
   - Reuse the 8-value pack helper for value and validity bitmaps.
   - Add exhaustive bitmap coverage and a BooleanBuilder benchmark.
   
   ## Benchmark
   
   Apple M1 Pro. 65,536 values. The builder is pre-reserved. Median of 5 runs.
   
   | Benchmark | upstream main | this PR | change |
   | --- | ---: | ---: | ---: |
   | BooleanBuilder / all false | 145 us | 18.6 us | 7.8x |
   | BooleanBuilder / alternating | 145 us | 18.6 us | 7.8x |
   | Boolean / all valid | 160 us | 34.4 us | 4.6x |
   | Boolean / 50% null | 161 us | 35.7 us | 4.5x |
   
   The first two rows use nil validity. The last two use the existing explicit-validity benchmark.
   
   ```text
   go test ./arrow/array -run '^$' -bench '^BenchmarkBooleanBuilderAppendValues$' -benchmem -benchtime=100ms -count=5
   go test ./arrow/array -run '^$' -bench '^BenchmarkAppendValuesWithValidity/boolean/' -benchmem -benchtime=100ms -count=5
   ```
   
   ## Tests
   
   - `go test ./arrow/array -count=1`
   - `go test -race ./arrow/array -count=1`
   - `go test ./arrow/bitutil ./arrow/compute/... -count=1`
   - `go vet ./arrow/array ./arrow/bitutil`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(arrow/array): batch-pack boolean values [arrow-go]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade merged PR #1237:
URL: https://github.com/apache/arrow-go/pull/1237


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(arrow/array): batch-pack boolean values [arrow-go]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #1237:
URL: https://github.com/apache/arrow-go/pull/1237#discussion_r3884081851


##########
arrow/array/booleanbuilder_benchmark_test.go:
##########
@@ -0,0 +1,72 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package array
+
+import (
+	"fmt"
+	"testing"
+
+	"github.com/apache/arrow-go/v18/arrow/memory"
+)
+
+func BenchmarkBooleanBuilderAppendValues(b *testing.B) {
+	const length = 65536
+	patterns := []struct {
+		name   string
+		values []bool
+	}{
+		{"all-false", makeBooleanBenchmarkValues(length, func(int) bool { return false })},
+		{"all-true", makeBooleanBenchmarkValues(length, func(int) bool { return true })},
+		{"alternating", makeBooleanBenchmarkValues(length, func(i int) bool { return i%2 == 0 })},
+		{"one-in-three", makeBooleanBenchmarkValues(length, func(i int) bool { return i%3 == 0 })},
+	}
+
+	for _, pattern := range patterns {
+		b.Run(pattern.name, func(b *testing.B) {
+			benchmarkAppendValues(b, func() (func(), func()) {
+				bldr := NewBooleanBuilder(memory.DefaultAllocator)
+				bldr.Reserve(length)
+				return func() {
+					bldr.AppendValues(pattern.values, nil)
+				}, bldr.Release
+			})
+		})
+	}
+}
+
+func BenchmarkBooleanBuilderAppendValuesSmall(b *testing.B) {
+	for _, length := range []int{1, 2, 3, 7, 8} {
+		b.Run(fmt.Sprintf("len=%d", length), func(b *testing.B) {
+			values := makeBooleanBenchmarkValues(length, func(i int) bool { return i%2 == 0 })
+			benchmarkAppendValues(b, func() (func(), func()) {

Review Comment:
   This benchmark delegates to `benchmarkAppendValues`, where builder creation and release occur outside the timed region. Because `b.N` is calibrated against only the roughly 65 ns append, the default benchmark performs millions of unmeasured allocations and releases. The first sub-benchmark did not finish within 180 seconds; even `-benchtime=1ms` took 5.9 seconds wall-clock. Please use a preallocated builder sized for the measured iterations, or include/reset lifecycle work without unbounded untimed setup.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(arrow/array): batch-pack boolean values [arrow-go]

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #1237:
URL: https://github.com/apache/arrow-go/pull/1237#discussion_r3881886633


##########
arrow/array/booleanbuilder.go:
##########
@@ -135,9 +135,7 @@ func (b *BooleanBuilder) AppendValues(v []bool, valid []bool) {
 	}
 
 	b.Reserve(len(v))
-	for i, vv := range v {
-		bitutil.SetBitTo(b.rawData, b.length+i, vv)
-	}
+	packBoolsToBitmap(b.rawData, b.length, v)

Review Comment:
   This regresses small `AppendValues` batches because `packBoolsToBitmap` adds setup overhead without packing a complete byte. Pre-reserved median results versus the exact base were: 1 value +35%, 2 values +23%, 3 values +15%, and 7 values +14%; the new implementation becomes faster at 8 values. Please retain the previous `SetBitTo` loop for small slices and add small-batch benchmark coverage.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org