This is an automated email from the ASF dual-hosted git repository.
Jefffrey 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 aa79c67359 add low card dictionary benchmarks (#10539)
aa79c67359 is described below
commit aa79c673593c89b808851a250f89854ba7ded6e9
Author: RIchard Baah <[email protected]>
AuthorDate: Wed Aug 5 09:57:11 2026 -0400
add low card dictionary benchmarks (#10539)
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->
- works towards #10465
- related to #2322
- this is pretty much striped from
https://github.com/apache/arrow-rs/pull/9520
# Rationale for this change
we need a way to measure the changes for future work in #10465
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
this PR adds 3 benchmarks that cover writting record batches of varying
cardinality's.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
# Are these changes tested?
n/a
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
If this PR claims a performance improvement, please include evidence
such as benchmark results.
-->
# Are there any user-facing changes?
no
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
Co-authored-by: rich-T-kid <[email protected]>
Co-authored-by: Jeffrey Vo <[email protected]>
---
parquet/benches/arrow_writer.rs | 43 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/parquet/benches/arrow_writer.rs b/parquet/benches/arrow_writer.rs
index 0e9900ee2f..cad8cf163e 100644
--- a/parquet/benches/arrow_writer.rs
+++ b/parquet/benches/arrow_writer.rs
@@ -18,9 +18,11 @@
#[macro_use]
extern crate criterion;
+use arrow_array::builder::StringDictionaryBuilder;
use criterion::{Bencher, Criterion, Throughput};
use parquet::arrow::ArrowWriter;
use parquet::basic::{Compression, Encoding, ZstdLevel};
+use rand::{Rng, distr::Alphanumeric};
use std::hint::black_box;
use std::io::Empty;
@@ -96,6 +98,38 @@ fn create_string_bench_batch(
true_density,
)?)
}
+// Creates a DictionaryArray with target cardinality
+fn create_low_card_dictionary_bench_batch(size: usize, cardinality: usize) ->
Result<RecordBatch> {
+ let mut rng = rand::rng();
+
+ // Generate `cardinality` unique random strings.
+ let categories: Vec<String> = (0..cardinality)
+ .map(|_| {
+ let len = rng.random_range(10..25);
+
+ (0..len).map(|_| rng.sample(Alphanumeric) as char).collect()
+ })
+ .collect();
+
+ let mut builder = StringDictionaryBuilder::<Int32Type>::new();
+
+ for i in 0..size {
+ builder.append_value(&categories[i % cardinality]);
+ }
+
+ let dict = builder.finish();
+
+ let schema = Schema::new(vec![Field::new(
+ "_1",
+ DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Utf8)),
+ false,
+ )]);
+
+ Ok(RecordBatch::try_new(
+ Arc::new(schema),
+ vec![Arc::new(dict)],
+ )?)
+}
/// 1 M short, fixed-width 8-byte strings. Exercises the BYTE_ARRAY hot path
/// for the case where individual values are small enough that the byte-budget
@@ -569,6 +603,15 @@ fn create_batches() -> Vec<(&'static str, RecordBatch)> {
let batch = create_string_dictionary_bench_batch(BATCH_SIZE, 0.25,
0.75).unwrap();
batches.push(("string_dictionary", batch));
+ let batch = create_low_card_dictionary_bench_batch(BATCH_SIZE,
20).unwrap();
+ batches.push(("string_dictionary_low_cardinality_20", batch));
+
+ let batch = create_low_card_dictionary_bench_batch(BATCH_SIZE,
100).unwrap();
+ batches.push(("string_dictionary_low_cardinality_100", batch));
+
+ let batch = create_low_card_dictionary_bench_batch(BATCH_SIZE,
400).unwrap();
+ batches.push(("string_dictionary_low_cardinality_400", batch));
+
let batch = create_string_bench_batch_non_null(BATCH_SIZE, 0.25,
0.75).unwrap();
batches.push(("string_non_null", batch));