This is an automated email from the ASF dual-hosted git repository.
etseidl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 0acd6e4a19 bench: add binary/string to dict cast benchmarks in
cast_kernels (#10763)
0acd6e4a19 is described below
commit 0acd6e4a19c4328219dc0df2f8c26fde366f4899
Author: RIchard Baah <[email protected]>
AuthorDate: Wed Aug 19 16:53:17 2026 -0400
bench: add binary/string to dict cast benchmarks in cast_kernels (#10763)
# Which issue does this PR close?
- works towards #10762.
# Rationale for this change
need a guidline to measure changes for #10762
# What changes are included in this PR?
new benchmarks to cover binary/string -> dict
# Are these changes tested?
n/a
# Are there any user-facing changes?
n/a
---
arrow/benches/cast_kernels.rs | 77 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/arrow/benches/cast_kernels.rs b/arrow/benches/cast_kernels.rs
index 9d76cce1b3..37d44663e5 100644
--- a/arrow/benches/cast_kernels.rs
+++ b/arrow/benches/cast_kernels.rs
@@ -172,6 +172,28 @@ fn build_float64_array_invalid_items(size: usize,
null_density: f32) -> ArrayRef
build_array_with_samples!(builder, size, null_density, invalid_values)
}
+// Builds a BinaryArray of `size` rows over `unique_count` distinct byte
strings.
+// `null_every` controls null density: Some(n) inserts a null every n rows,
None means no nulls.
+// Binary and Utf8 both route through pack_byte_to_dictionary, so binary
covers both paths.
+fn build_binary_array_for_dict_cast(
+ size: usize,
+ unique_count: usize,
+ null_every: Option<usize>,
+) -> ArrayRef {
+ let values: Vec<Vec<u8>> = (0..unique_count)
+ .map(|i| format!("value{i:08}").into_bytes())
+ .collect();
+ let mut builder = BinaryBuilder::with_capacity(size, size * 10);
+ for i in 0..size {
+ if null_every.is_some_and(|n| i % n == 0) {
+ builder.append_null();
+ } else {
+ builder.append_value(&values[i % unique_count]);
+ }
+ }
+ Arc::new(builder.finish())
+}
+
fn build_dict_array(size: usize) -> ArrayRef {
let values = StringArray::from_iter([
Some("small"),
@@ -257,6 +279,13 @@ fn add_benchmark(c: &mut Criterion) {
let string_array = build_string_array(512);
let wide_string_array = cast(&string_array, &DataType::LargeUtf8).unwrap();
+ let binary_low_card = build_binary_array_for_dict_cast(10_000, 25,
Some(20));
+ let binary_med_card = build_binary_array_for_dict_cast(10_000, 500,
Some(20));
+ let binary_high_card = build_binary_array_for_dict_cast(10_000, 2_500,
Some(20));
+ let binary_low_card_no_nulls = build_binary_array_for_dict_cast(10_000,
25, None);
+ let binary_med_card_no_nulls = build_binary_array_for_dict_cast(10_000,
500, None);
+ let binary_high_card_no_nulls = build_binary_array_for_dict_cast(10_000,
2_500, None);
+
let dict_array = build_dict_array(10_000);
let nested_dict_array = build_nested_dict_array(10_000);
let string_view_array = cast(&dict_array, &DataType::Utf8View).unwrap();
@@ -403,6 +432,54 @@ fn add_benchmark(c: &mut Criterion) {
)
})
});
+ c.bench_function("cast binary to dict low cardinality", |b| {
+ b.iter(|| {
+ cast_array(
+ &binary_low_card,
+ DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Binary)),
+ )
+ })
+ });
+ c.bench_function("cast binary to dict medium cardinality", |b| {
+ b.iter(|| {
+ cast_array(
+ &binary_med_card,
+ DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Binary)),
+ )
+ })
+ });
+ c.bench_function("cast binary to dict high cardinality", |b| {
+ b.iter(|| {
+ cast_array(
+ &binary_high_card,
+ DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Binary)),
+ )
+ })
+ });
+ c.bench_function("cast binary to dict low cardinality no nulls", |b| {
+ b.iter(|| {
+ cast_array(
+ &binary_low_card_no_nulls,
+ DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Binary)),
+ )
+ })
+ });
+ c.bench_function("cast binary to dict medium cardinality no nulls", |b| {
+ b.iter(|| {
+ cast_array(
+ &binary_med_card_no_nulls,
+ DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Binary)),
+ )
+ })
+ });
+ c.bench_function("cast binary to dict high cardinality no nulls", |b| {
+ b.iter(|| {
+ cast_array(
+ &binary_high_card_no_nulls,
+ DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Binary)),
+ )
+ })
+ });
c.bench_function("cast string view to dict", |b| {
b.iter(|| {
cast_array(