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 05af6427d9 bench(arrow-ipc): add StreamReader benchmark for many
dictionaries (#12070)
05af6427d9 is described below
commit 05af6427d96e9cb173fb25dffe093fb3217bd27b
Author: Alfonso Subiotto Marqués <[email protected]>
AuthorDate: Wed Nov 4 14:46:19 2026 +0000
bench(arrow-ipc): add StreamReader benchmark for many dictionaries (#12070)
# Which issue does this PR close?
- Part of apache/arrow-rs#12069
# Rationale for this change
No IPC reader benchmark covers streams with many dictionary batches,
where the reader looks up each dictionary's field in the schema. Per
[CONTRIBUTING.md](https://github.com/apache/arrow-rs/blob/main/CONTRIBUTING.md#performance-improvements),
this lands ahead of the optimization so it can run on the benchmark
runner.
# What changes are included in this PR?
Adds
`StreamReader/dictionaries/1000_columns/{4,4096}_distinct/{flat,list}`:
a stream with one batch of 1000 string dictionary columns. Each column
holds the same 4096 values with 4 or 4096 distinct values, either
directly (`flat`) or grouped into lists of 4 (`list`).
# Are these changes tested?
Benchmark only.
# Are there any significant user-facing changes?
No.
The benchmark was written with AI assistance (Claude) and reviewed by
me.
---
arrow-ipc/benches/ipc_reader.rs | 53 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 51 insertions(+), 2 deletions(-)
diff --git a/arrow-ipc/benches/ipc_reader.rs b/arrow-ipc/benches/ipc_reader.rs
index c73e3d5dee..94955a3560 100644
--- a/arrow-ipc/benches/ipc_reader.rs
+++ b/arrow-ipc/benches/ipc_reader.rs
@@ -15,8 +15,11 @@
// specific language governing permissions and limitations
// under the License.
-use arrow_array::builder::{Date32Builder, Decimal128Builder, Int32Builder};
-use arrow_array::{FixedSizeBinaryArray, RecordBatch, builder::StringBuilder};
+use arrow_array::builder::{
+ Date32Builder, Decimal128Builder, Int32Builder, ListBuilder,
StringDictionaryBuilder,
+};
+use arrow_array::types::Int32Type;
+use arrow_array::{ArrayRef, FixedSizeBinaryArray, RecordBatch,
builder::StringBuilder};
use arrow_buffer::Buffer;
use arrow_ipc::convert::try_fb_to_schema;
use arrow_ipc::reader::{FileDecoder, FileReader, StreamReader,
read_footer_length};
@@ -185,6 +188,52 @@ fn criterion_benchmark(c: &mut Criterion) {
}
})
});
+
+ let num_columns = 1000;
+ for num_distinct in [4, 4096] {
+ for (layout, list) in [("flat", false), ("list", true)] {
+ let buffer = dictionary_ipc_stream(num_columns, num_distinct,
list);
+ let name = format!(
+
"StreamReader/dictionaries/{num_columns}_columns/{num_distinct}_distinct/{layout}"
+ );
+ group.bench_function(name, |b| {
+ b.iter(|| {
+ let mut reader = StreamReader::try_new(buffer.as_slice(),
None).unwrap();
+ reader.next().unwrap().unwrap();
+ assert!(reader.next().is_none());
+ })
+ });
+ }
+ }
+}
+
+/// Return an IPC stream with one record batch of `num_columns` string
dictionary columns. Each
+/// column holds the same 4096 values with `num_distinct` distinct values,
either directly or, with
+/// `list`, grouped into lists of 4.
+fn dictionary_ipc_stream(num_columns: usize, num_distinct: usize, list: bool)
-> Vec<u8> {
+ let values: Vec<String> = (0..4096)
+ .map(|i| format!("value_{}", i % num_distinct))
+ .collect();
+ let column: ArrayRef = if list {
+ let mut builder =
ListBuilder::new(StringDictionaryBuilder::<Int32Type>::new());
+ for chunk in values.chunks(4) {
+ builder.append_value(chunk.iter().map(Some));
+ }
+ Arc::new(builder.finish())
+ } else {
+ let mut builder = StringDictionaryBuilder::<Int32Type>::new();
+ builder.extend(values.iter().map(Some));
+ Arc::new(builder.finish())
+ };
+ let batch = RecordBatch::try_from_iter(
+ (0..num_columns).map(|i| (format!("c{i}"), Arc::clone(&column))),
+ )
+ .unwrap();
+ let mut buffer = Vec::new();
+ let mut writer = StreamWriter::try_new(&mut buffer,
batch.schema().as_ref()).unwrap();
+ writer.write(&batch).unwrap();
+ writer.finish().unwrap();
+ buffer
}
/// Return an IPC stream with 10 record batches