This is an automated email from the ASF dual-hosted git repository.
alamb 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 b71c8f208a perf: add decimal and fsb arrow_writer bench (#10388)
b71c8f208a is described below
commit b71c8f208a869958944348ace6f66f0a19448759
Author: Michal Piatkowski <[email protected]>
AuthorDate: Mon Jul 20 22:13:27 2026 +0200
perf: add decimal and fsb arrow_writer bench (#10388)
# 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.
-->
- Related to
https://github.com/apache/arrow-rs/pull/10364#pullrequestreview-4726321372.
# Rationale for this change
<!--
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?
<!--
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?
<!--
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?
<!--
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.
-->
---
arrow/src/util/data_gen.rs | 30 ++++++++++++++++++++++++++++++
parquet/benches/arrow_writer.rs | 33 +++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/arrow/src/util/data_gen.rs b/arrow/src/util/data_gen.rs
index b5eb9efbc3..1953519df4 100644
--- a/arrow/src/util/data_gen.rs
+++ b/arrow/src/util/data_gen.rs
@@ -181,6 +181,8 @@ pub fn create_random_array(
crate::compute::cast(&v, d)?
}
Map(_, _) => create_random_map_array(field, size, null_density,
true_density)?,
+ Decimal32(_, _) => create_random_decimal_array(field, size,
null_density)?,
+ Decimal64(_, _) => create_random_decimal_array(field, size,
null_density)?,
Decimal128(_, _) => create_random_decimal_array(field, size,
null_density)?,
Decimal256(_, _) => create_random_decimal_array(field, size,
null_density)?,
RunEndEncoded(index, value) => {
@@ -205,6 +207,34 @@ fn create_random_decimal_array(field: &Field, size: usize,
null_density: f32) ->
let mut rng = seedable_rng();
match field.data_type() {
+ DataType::Decimal32(precision, scale) => {
+ let values = (0..size)
+ .map(|_| {
+ if rng.random::<f32>() < null_density {
+ None
+ } else {
+ Some(rng.random::<i32>())
+ }
+ })
+ .collect::<Vec<_>>();
+ Ok(Arc::new(
+
Decimal32Array::from(values).with_precision_and_scale(*precision, *scale)?,
+ ))
+ }
+ DataType::Decimal64(precision, scale) => {
+ let values = (0..size)
+ .map(|_| {
+ if rng.random::<f32>() < null_density {
+ None
+ } else {
+ Some(rng.random::<i64>())
+ }
+ })
+ .collect::<Vec<_>>();
+ Ok(Arc::new(
+
Decimal64Array::from(values).with_precision_and_scale(*precision, *scale)?,
+ ))
+ }
DataType::Decimal128(precision, scale) => {
let values = (0..size)
.map(|_| {
diff --git a/parquet/benches/arrow_writer.rs b/parquet/benches/arrow_writer.rs
index 073716e2f3..adc4dcc9ea 100644
--- a/parquet/benches/arrow_writer.rs
+++ b/parquet/benches/arrow_writer.rs
@@ -251,6 +251,22 @@ fn create_float_bench_batch_with_nans(size: usize,
nan_density: f32) -> Result<R
)?)
}
+fn create_decimal_bench_batch(size: usize, null_density: f32) ->
Result<RecordBatch> {
+ let fields = vec![
+ Field::new("_1", Decimal32Type::DEFAULT_TYPE, false),
+ Field::new("_2", Decimal64Type::DEFAULT_TYPE, false),
+ Field::new("_3", Decimal128Type::DEFAULT_TYPE, false),
+ Field::new("_4", Decimal256Type::DEFAULT_TYPE, false),
+ ];
+ let schema = Schema::new(fields);
+ Ok(create_random_batch(
+ Arc::new(schema),
+ size,
+ null_density,
+ 0.75,
+ )?)
+}
+
fn create_list_primitive_bench_batch(
size: usize,
null_density: f32,
@@ -332,6 +348,17 @@ fn create_struct_bench_batch(size: usize, null_density:
f32) -> Result<RecordBat
)?)
}
+fn create_fsb_bench_batch(size: usize, null_density: f32, len: i32) ->
Result<RecordBatch> {
+ let fields = vec![Field::new("_1", DataType::FixedSizeBinary(len), true)];
+ let schema = Schema::new(fields);
+ Ok(create_random_batch(
+ Arc::new(schema),
+ size,
+ null_density,
+ 0.75,
+ )?)
+}
+
fn create_nested_list_bench_batch(size: usize, null_density: f32) ->
Result<RecordBatch> {
// List<List<Int32>> — exercises the nested repetition (non-batched) path
let fields = vec![Field::new(
@@ -528,6 +555,9 @@ fn create_batches() -> Vec<(&'static str, RecordBatch)> {
let batch = create_float_bench_batch_with_nans(BATCH_SIZE, 0.5).unwrap();
batches.push(("float_with_nans", batch));
+ let batch = create_decimal_bench_batch(BATCH_SIZE, 0.75).unwrap();
+ batches.push(("decimal", batch));
+
let batch = create_list_primitive_bench_batch(BATCH_SIZE, 0.25,
0.75).unwrap();
batches.push(("list_primitive", batch));
@@ -552,6 +582,9 @@ fn create_batches() -> Vec<(&'static str, RecordBatch)> {
let batch = create_struct_bench_batch(BATCH_SIZE, 1.0).unwrap();
batches.push(("struct_all_null", batch));
+ let batch = create_fsb_bench_batch(BATCH_SIZE, 0.9, 16).unwrap();
+ batches.push(("fsb", batch));
+
let batch = create_nested_list_bench_batch(BATCH_SIZE, 0.25).unwrap();
batches.push(("list_nested", batch));