From 8aa91e519aa25587b7c79e08b2bb69b905b23927 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Tue, 23 Jul 2024 18:24:40 +0300 Subject: [PATCH] Make bool_or an alias for max_boolean (#6100) Improves `cargo bench --bench aggregate_kernels -- "bool/or"` throughput by 68%-22366% on my machine --- arrow-arith/src/aggregate.rs | 5 +---- arrow/benches/aggregate_kernels.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arrow-arith/src/aggregate.rs b/arrow-arith/src/aggregate.rs index ae4a5b008a83..f526268bf49e 100644 --- a/arrow-arith/src/aggregate.rs +++ b/arrow-arith/src/aggregate.rs @@ -674,10 +674,7 @@ pub fn bool_and(array: &BooleanArray) -> Option { /// /// Returns `None` if the array is empty or only contains null values. pub fn bool_or(array: &BooleanArray) -> Option { - if array.null_count() == array.len() { - return None; - } - Some(array.true_count() != 0) + max_boolean(array) } /// Returns the sum of values in the primitive array. diff --git a/arrow/benches/aggregate_kernels.rs b/arrow/benches/aggregate_kernels.rs index 71cd24278424..9bb866f364a4 100644 --- a/arrow/benches/aggregate_kernels.rs +++ b/arrow/benches/aggregate_kernels.rs @@ -82,35 +82,53 @@ fn add_benchmark(c: &mut Criterion) { .bench_function("max nonnull mixed", |b| { b.iter(|| max_boolean(&nonnull_bools_mixed)) }) + .bench_function("or nonnull mixed", |b| { + b.iter(|| bool_or(&nonnull_bools_mixed)) + }) .bench_function("min nonnull false", |b| { b.iter(|| min_boolean(&nonnull_bools_all_false)) }) .bench_function("max nonnull false", |b| { b.iter(|| max_boolean(&nonnull_bools_all_false)) }) + .bench_function("or nonnull false", |b| { + b.iter(|| bool_or(&nonnull_bools_all_false)) + }) .bench_function("min nonnull true", |b| { b.iter(|| min_boolean(&nonnull_bools_all_true)) }) .bench_function("max nonnull true", |b| { b.iter(|| max_boolean(&nonnull_bools_all_true)) }) + .bench_function("or nonnull true", |b| { + b.iter(|| bool_or(&nonnull_bools_all_true)) + }) .bench_function("min nullable mixed", |b| { b.iter(|| min_boolean(&nullable_bool_mixed)) }) .bench_function("max nullable mixed", |b| { b.iter(|| max_boolean(&nullable_bool_mixed)) }) + .bench_function("or nullable mixed", |b| { + b.iter(|| bool_or(&nullable_bool_mixed)) + }) .bench_function("min nullable false", |b| { b.iter(|| min_boolean(&nullable_bool_all_false)) }) .bench_function("max nullable false", |b| { b.iter(|| max_boolean(&nullable_bool_all_false)) }) + .bench_function("or nullable false", |b| { + b.iter(|| bool_or(&nullable_bool_all_false)) + }) .bench_function("min nullable true", |b| { b.iter(|| min_boolean(&nullable_bool_all_true)) }) .bench_function("max nullable true", |b| { b.iter(|| max_boolean(&nullable_bool_all_true)) + }) + .bench_function("or nullable true", |b| { + b.iter(|| bool_or(&nullable_bool_all_true)) }); } }