From bec4031b607bb9e15b1b656a739d5d8e5a59afa1 Mon Sep 17 00:00:00 2001 From: rich-T-kid Date: Sat, 15 Aug 2026 23:13:15 -0400 Subject: [PATCH 1/3] introduce take_n_true benchmark --- arrow-array/benches/boolean_array.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arrow-array/benches/boolean_array.rs b/arrow-array/benches/boolean_array.rs index 03b601075bb8..c75b1df5ed3c 100644 --- a/arrow-array/benches/boolean_array.rs +++ b/arrow-array/benches/boolean_array.rs @@ -70,6 +70,19 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function(&format!("has_false(nulls_all_true, {len})"), |b| { b.iter(|| hint::black_box(&with_nulls).has_false()); }); + // take_n_true: mixed true/false + let bool_vec: Vec = (0..len) + .map(|idx| if idx % 3 == 0 { false } else { true }) + .collect(); + let mixed_boolean_array_unique = BooleanArray::from(bool_vec.clone()); + c.bench_function(&format!("take_n_true({})", len / 2), |b| { + b.iter(|| hint::black_box(&mixed_boolean_array_unique)); + }); + let mixed_boolean_array_shared = BooleanArray::from(bool_vec); + let shared_array = mixed_boolean_array_shared.clone(); + c.bench_function(&format!("take_n_true({})", len / 2), |b| { + b.iter(|| hint::black_box(&shared_array)); + }); } } From 4f35c19a69bc37e96d9d3bc264e2df96203ae426 Mon Sep 17 00:00:00 2001 From: rich-T-kid Date: Sat, 15 Aug 2026 23:20:42 -0400 Subject: [PATCH 2/3] minor tweak --- arrow-array/benches/boolean_array.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arrow-array/benches/boolean_array.rs b/arrow-array/benches/boolean_array.rs index c75b1df5ed3c..3655e62aa997 100644 --- a/arrow-array/benches/boolean_array.rs +++ b/arrow-array/benches/boolean_array.rs @@ -70,18 +70,27 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function(&format!("has_false(nulls_all_true, {len})"), |b| { b.iter(|| hint::black_box(&with_nulls).has_false()); }); + // take_n_true: mixed true/false let bool_vec: Vec = (0..len) .map(|idx| if idx % 3 == 0 { false } else { true }) .collect(); - let mixed_boolean_array_unique = BooleanArray::from(bool_vec.clone()); c.bench_function(&format!("take_n_true({})", len / 2), |b| { - b.iter(|| hint::black_box(&mixed_boolean_array_unique)); + b.iter_batched( + || BooleanArray::from(bool_vec.clone()), // fresh buffer, strong_count == 1 + |arr| hint::black_box(arr).take_n_true(len / 2), + BatchSize::SmallInput, + ); }); + // underlying buffer is shared let mixed_boolean_array_shared = BooleanArray::from(bool_vec); let shared_array = mixed_boolean_array_shared.clone(); c.bench_function(&format!("take_n_true({})", len / 2), |b| { - b.iter(|| hint::black_box(&shared_array)); + b.iter_batched( + || shared_array.clone(), // strong_count >= 2, forces copy path + |arr| hint::black_box(arr).take_n_true(len / 2), + BatchSize::SmallInput, + ); }); } } From 03ba265c91abde6b6a2bbad9abe1e09db270c030 Mon Sep 17 00:00:00 2001 From: rich-T-kid Date: Sat, 15 Aug 2026 23:23:55 -0400 Subject: [PATCH 3/3] fix lint --- arrow-array/benches/boolean_array.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arrow-array/benches/boolean_array.rs b/arrow-array/benches/boolean_array.rs index 3655e62aa997..0c0cac323a97 100644 --- a/arrow-array/benches/boolean_array.rs +++ b/arrow-array/benches/boolean_array.rs @@ -72,9 +72,7 @@ fn criterion_benchmark(c: &mut Criterion) { }); // take_n_true: mixed true/false - let bool_vec: Vec = (0..len) - .map(|idx| if idx % 3 == 0 { false } else { true }) - .collect(); + let bool_vec: Vec = (0..len).map(|idx| idx % 3 != 0).collect(); c.bench_function(&format!("take_n_true({})", len / 2), |b| { b.iter_batched( || BooleanArray::from(bool_vec.clone()), // fresh buffer, strong_count == 1