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 e4df827bc1 perf(ipc): benchmark stream encoder (#10447)
e4df827bc1 is described below

commit e4df827bc1ee5456bb7d1856c5a6f96bf14541d0
Author: Phoenix <[email protected]>
AuthorDate: Thu Jul 30 22:45:56 2026 +0800

    perf(ipc): benchmark stream encoder (#10447)
    
    # 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.
    -->
    
    - Closes #10373.
    
    # 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.
    -->
    
    Add a `StreamEncoder` benchmarks so that we can catch regressions
    without measuring sink IO.
    
    
    # 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?
    Yes
    
    <!--
    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.
    -->
    
    ---------
    
    Signed-off-by: Jiawei Zhao <[email protected]>
---
 arrow-ipc/benches/ipc_writer.rs | 59 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/arrow-ipc/benches/ipc_writer.rs b/arrow-ipc/benches/ipc_writer.rs
index 5050ff6cd1..5364049fb9 100644
--- a/arrow-ipc/benches/ipc_writer.rs
+++ b/arrow-ipc/benches/ipc_writer.rs
@@ -21,9 +21,12 @@ use arrow_array::builder::{
 };
 use arrow_array::types::UInt32Type;
 use arrow_ipc::CompressionType;
-use arrow_ipc::writer::{DictionaryHandling, FileWriter, IpcWriteOptions, 
StreamWriter};
+use arrow_ipc::writer::{
+    DictionaryHandling, FileWriter, IpcWriteOptions, StreamEncoder, 
StreamWriter,
+};
 use arrow_schema::{DataType, Field, Schema};
 use criterion::{Criterion, criterion_group, criterion_main};
+use std::hint::black_box;
 use std::sync::Arc;
 
 fn criterion_benchmark(c: &mut Criterion) {
@@ -60,6 +63,32 @@ fn criterion_benchmark(c: &mut Criterion) {
         })
     });
 
+    group.bench_function("StreamEncoder/encode_10", |b| {
+        let batch = create_batch(8192, true);
+        b.iter(move || {
+            let mut encoder = 
StreamEncoder::try_new(batch.schema().as_ref()).unwrap();
+            for _ in 0..10 {
+                black_box(encoder.encode(&batch).unwrap());
+            }
+            black_box(encoder.finish().unwrap());
+        })
+    });
+
+    group.bench_function("StreamEncoder/encode_10/zstd", |b| {
+        let batch = create_batch(8192, true);
+        b.iter(move || {
+            let options = IpcWriteOptions::default()
+                .try_with_compression(Some(CompressionType::ZSTD))
+                .unwrap();
+            let mut encoder =
+                StreamEncoder::try_new_with_options(batch.schema().as_ref(), 
options).unwrap();
+            for _ in 0..10 {
+                black_box(encoder.encode(&batch).unwrap());
+            }
+            black_box(encoder.finish().unwrap());
+        })
+    });
+
     group.bench_function("FileWriter/write_10", |b| {
         let batch = create_batch(8192, true);
         let mut buffer = Vec::with_capacity(2 * 1024 * 1024);
@@ -87,6 +116,18 @@ fn criterion_benchmark(c: &mut Criterion) {
         })
     });
 
+    group.bench_function("StreamEncoder/encode_10/dict", |b| {
+        let batches = create_unique_dict_batches(10, 8192);
+        let schema = batches[0].schema();
+        b.iter(move || {
+            let mut encoder = StreamEncoder::try_new(schema.as_ref()).unwrap();
+            for batch in &batches {
+                black_box(encoder.encode(batch).unwrap());
+            }
+            black_box(encoder.finish().unwrap());
+        })
+    });
+
     group.bench_function("StreamWriter/write_10/dict/delta", |b| {
         let batches = create_delta_dict_batches(10, 8192);
         let schema = batches[0].schema();
@@ -109,6 +150,22 @@ fn criterion_benchmark(c: &mut Criterion) {
         })
     });
 
+    group.bench_function("StreamEncoder/encode_10/dict/delta", |b| {
+        let batches = create_delta_dict_batches(10, 8192);
+        let schema = batches[0].schema();
+        let options =
+            
IpcWriteOptions::default().with_dictionary_handling(DictionaryHandling::Delta);
+
+        b.iter(move || {
+            let mut encoder =
+                StreamEncoder::try_new_with_options(schema.as_ref(), 
options.clone()).unwrap();
+            for batch in &batches {
+                black_box(encoder.encode(batch).unwrap());
+            }
+            black_box(encoder.finish().unwrap());
+        })
+    });
+
     // The file writer rejects dictionary replacement, so only the delta case 
is
     // exercised here (growing dictionaries that are prefixes of one another).
     group.bench_function("FileWriter/write_10/dict/delta", |b| {

Reply via email to