From 1d44d7f211e20418a9dde2eec6a0ec09eaea8bad Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 2 Jul 2026 13:03:13 -0400 Subject: [PATCH 1/2] introduce zero copy path when tonic returns an aligned buffer --- arrow-flight/src/decode.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arrow-flight/src/decode.rs b/arrow-flight/src/decode.rs index 1f64924932d4..d03f73a09ffa 100644 --- a/arrow-flight/src/decode.rs +++ b/arrow-flight/src/decode.rs @@ -336,8 +336,18 @@ impl FlightDataDecoder { "Unable to convert flight data header to a record batch".to_string(), ) })?; + let buffer = { + // Arrow spec requires 64-byte buffer alignment for SIMD; + // see https://arrow.apache.org/docs/format/Columnar.html#buffer-alignment-and-padding + // reuse the allocation if already aligned, otherwise copy into a fresh aligned buffer. + if data.data_body.as_ptr() as usize % 64 == 0 { + &Buffer::from(data.data_body.clone()) + } else { + &Buffer::from(data.data_body.as_ref()) + } + }; let batch = arrow_ipc::reader::RecordBatchDecoder::try_new( - &Buffer::from(data.data_body.as_ref()), + buffer, record_batch, Arc::clone(&state.schema), &state.dictionaries_by_field, From 1af08d784e6568d8eae54df38f20e44b5eb1c8c0 Mon Sep 17 00:00:00 2001 From: Richard Date: Thu, 2 Jul 2026 13:12:55 -0400 Subject: [PATCH 2/2] clear space --- arrow-flight/src/decode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-flight/src/decode.rs b/arrow-flight/src/decode.rs index d03f73a09ffa..a52c35bc0fcf 100644 --- a/arrow-flight/src/decode.rs +++ b/arrow-flight/src/decode.rs @@ -339,7 +339,7 @@ impl FlightDataDecoder { let buffer = { // Arrow spec requires 64-byte buffer alignment for SIMD; // see https://arrow.apache.org/docs/format/Columnar.html#buffer-alignment-and-padding - // reuse the allocation if already aligned, otherwise copy into a fresh aligned buffer. + // reuse the allocation if already aligned, otherwise copy into a fresh aligned buffer. if data.data_body.as_ptr() as usize % 64 == 0 { &Buffer::from(data.data_body.clone()) } else {