Repository navigation
Conversation
…at a time `append_slice` appended one bit at a time, doing a byte-level read-modify-write and an unpredictable branch for every boolean. Pack 8 booleans into a byte with a multiplication and a constant shift, and store whole bytes; only the partial byte at the head and the trailing partial byte need per-bit bookkeeping. `len` is still advanced up front, so the bookkeeping is unchanged, and the padding bits above the final bit stay zero. Adds tests for unaligned head/tail bytes, all-true/all-false slices, empty slices, zeroed padding, and a randomized comparison against a bit-by-bit reference.
Signed-off-by: Ruihang Xia <[email protected]>
|
run benchmark builder |
1 similar comment
|
run benchmark builder |
|
🤖 Benchmark starting (GKE) | trigger Target: builder Sharding factor: 1 (1 workers). Comparing perf/boolean-append-slice (fffeec0) to 9ffd63d (merge-base) diff Run configurationrun benchmark builder
env:
BENCH_FILTER: bench_bool
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark starting (GKE) | trigger Target: builder Sharding factor: 1 (1 workers). Comparing perf/boolean-append-slice (fffeec0) to 9ffd63d (merge-base) diff Run configurationrun benchmark builder
env:
BENCH_FILTER: bench_bool
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark failed or incomplete (GKE) | trigger Target: builder Comparing perf/boolean-append-slice (fffeec0) to 9ffd63d (merge-base) diff Run configurationrun benchmark builder
env:
BENCH_FILTER: bench_bool
shards: 1
Errors / missing shardsPer-runner informationbuilder — shard 1/1Runner information unavailable. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: builder Comparing perf/boolean-append-slice (fffeec0) to 9ffd63d (merge-base) diff Run configurationrun benchmark builder
env:
BENCH_FILTER: bench_bool
shards: 1
DetailsPer-runner informationbuilder — shard 1/1Node: gk3-benchmark-cluster-nap-17yz8u0s-c78dad10-gvbd Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench builderCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
run benchmark builder |
|
🤖 Benchmark starting (GKE) | trigger Target: builder Sharding factor: 1 (1 workers). Comparing perf/boolean-append-slice (fffeec0) to 9ffd63d (merge-base) diff Run configurationrun benchmark builder
env:
BENCH_FILTER: bench_bool
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: builder Comparing perf/boolean-append-slice (fffeec0) to 9ffd63d (merge-base) diff Run configurationrun benchmark builder
env:
BENCH_FILTER: bench_bool
shards: 1
DetailsPer-runner informationbuilder — shard 1/1Node: gk3-benchmark-cluster-nap-1embnon5-4daa0a8c-89kl Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench builderCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
@waynexia could you rebase this PR, i'm interested in reviewing it |
|
Isn't this redundant to #12024 that already merged? |
|
it seems that way, we need to rebase and re-run the benchmarks |
Rich-T-kid
left a comment
There was a problem hiding this comment.
can we re-base this Pr and re-run the benchmarks @waynexia
|
I mean, do we even need to do that? I read the code. It’s doing the same thing. Maybe the author can explain how it’s different before we burn more reviewer cycles and benchmarking infrastructure. |
|
Ahh, I rebased this branch against the latest main and ... all code diffs are gone. I read #12024 and yes, they are very identical 🤣 Apologize for this, I haven't checked the PR list when opening this one 🙈 I'll be more careful next time scanning for optimizations. Closing this ticket |

Which issue does this PR close?
Rationale for this change
BooleanBufferBuilder::append_slice(which also backsBooleanBuilder::append_slice,NullBufferBuilder::append_slice,PrimitiveBuilder::append_values, andBooleanBuffer::from(&[bool])) previously appended booleans one bit at a time:This had two main performance bottlenecks:
if *v), causing frequent branch mispredictions on unpredictable boolean inputs.set_bit_rawperforms a byte read, bitwise OR, and store for everytruebit, creating a store-to-load dependency chain on the same target byte up to 8 times.Packing 8 booleans at a time into a single byte without branches and storing whole bytes eliminates both the branch mispredictions and the per-bit read-modify-write traffic.
Human Rationale
I'm trying to find something to burn my token, and come across this. This PR is fully written by AI. I have read and understand all logic changes. It increases complexity, but given that this part is not likely to be touched too often, I thought it was acceptable.
What changes are included in this PR?
BooleanBufferBuilder::append_sliceinto three phases:as_chunks::<8>()) using a branchless SWAR multiplication ((u64::from_le_bytes(bytes).wrapping_mul(0x0102_0408_1020_4080) >> 56) as u8) and write full bytes directly to the buffer.wrapping_mul(0x0102_0408_1020_4080) >> 56)equals to 8 continuous "shift-left + OR"< 8booleans into the final byte, keeping the trailing padding bits zeroed.arrow-buffercovering unaligned head/tail combinations, all-true/all-false inputs, empty slices, zeroed padding invariants, and randomized comparisons against a reference bit-by-bit implementation.Are these changes tested?
Yes
Performance can also be verified with the existing
bench_boolbenchmark inarrow/benches/builder.rs(cargo bench -p arrow --bench builder -- bench_bool).On my local env, depends on the scenario, this patch can achieve at least 5x improvement on microbenchmark, except one bad case that append 1 bit a time
Are there any significant user-facing changes?
No.