This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] 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 b65bab9c2f Add benchmark for `PrimitiveDictionaryBuilder` (#12060)
b65bab9c2f is described below
commit b65bab9c2f2e02d80a65338b262861a1a7dbcb4c
Author: Matthew Katz <[email protected]>
AuthorDate: Tue Nov 3 20:08:09 2026 +0000
Add benchmark for `PrimitiveDictionaryBuilder` (#12060)
# Which issue does this PR close?
- Part of #12055
# Rationale for this change
Adds a benchmark for `PrimitiveDictionaryBuilder` so #12057 can be
compared against main on the benchmark runner.
# What changes are included in this PR?
A `primitive_dictionary_builder` benchmark.
# Are these changes tested?
This PR only adds a benchmark.
# Are there any significant user-facing changes?
No.
This PR was drafted with AI assistance. I reviewed all changes and take
responsibility for them.
---------
Signed-off-by: Matt Katz <[email protected]>
---
arrow/Cargo.toml | 4 ++
arrow/benches/primitive_dictionary_builder.rs | 79 +++++++++++++++++++++++++++
2 files changed, 83 insertions(+)
diff --git a/arrow/Cargo.toml b/arrow/Cargo.toml
index cb8746d585..12b5349ae0 100644
--- a/arrow/Cargo.toml
+++ b/arrow/Cargo.toml
@@ -268,6 +268,10 @@ required-features = ["test_utils"]
name = "string_dictionary_builder"
harness = false
+[[bench]]
+name = "primitive_dictionary_builder"
+harness = false
+
[[bench]]
name = "string_run_builder"
harness = false
diff --git a/arrow/benches/primitive_dictionary_builder.rs
b/arrow/benches/primitive_dictionary_builder.rs
new file mode 100644
index 0000000000..cbfea0c6d1
--- /dev/null
+++ b/arrow/benches/primitive_dictionary_builder.rs
@@ -0,0 +1,79 @@
+// 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.
+use arrow::array::PrimitiveDictionaryBuilder;
+use arrow::datatypes::{ArrowPrimitiveType, Decimal128Type, Int32Type,
UInt32Type, UInt64Type};
+use criterion::{Criterion, criterion_group, criterion_main};
+use rand::distr::{Distribution, StandardUniform};
+use rand::{RngExt, rng};
+
+/// Note: this is best effort, not all values are necessarily present or unique
+fn build_values<T: Copy>(dict_size: usize, total_size: usize) -> Vec<T>
+where
+ StandardUniform: Distribution<T>,
+{
+ let mut rng = rng();
+ let values: Vec<T> = (0..dict_size).map(|_| rng.random()).collect();
+
+ (0..total_size)
+ .map(|_| values[rng.random_range(0..dict_size)])
+ .collect()
+}
+
+fn bench_values<V>(c: &mut Criterion, name: &str)
+where
+ V: ArrowPrimitiveType,
+ StandardUniform: Distribution<V::Native>,
+{
+ let mut group = c.benchmark_group("primitive_dictionary_builder");
+
+ let mut do_bench = |dict_size: usize, total_size: usize| {
+ group.bench_function(
+ format!("({name}, dict_size:{dict_size}, len:{total_size})"),
+ |b| {
+ let values = build_values::<V::Native>(dict_size, total_size);
+ b.iter(|| {
+ let mut builder = PrimitiveDictionaryBuilder::<Int32Type,
V>::with_capacity(
+ values.len(),
+ dict_size,
+ );
+
+ for val in &values {
+ builder.append(*val).unwrap();
+ }
+
+ builder.finish();
+ })
+ },
+ );
+ };
+
+ do_bench(20, 1000);
+ do_bench(100, 10000);
+ do_bench(10000, 100000);
+ do_bench(8192, 512000);
+
+ group.finish();
+}
+
+fn criterion_benchmark(c: &mut Criterion) {
+ bench_values::<UInt32Type>(c, "UInt32");
+ bench_values::<UInt64Type>(c, "UInt64");
+ bench_values::<Decimal128Type>(c, "Decimal128");
+}
+
+criterion_group!(benches, criterion_benchmark);
+criterion_main!(benches);