tustvold commented on code in PR #6930:
URL: https://github.com/apache/arrow-rs/pull/6930#discussion_r1903046691


##########
parquet/src/arrow/array_reader/byte_view_array.rs:
##########
@@ -308,18 +308,29 @@ impl ByteViewArrayDecoderPlain {
         validate_utf8: bool,
     ) -> Self {
         Self {
-            buf,
+            buf: Buffer::from_external_bytes(buf),
             offset: 0,
             max_remaining_values: num_values.unwrap_or(num_levels),
             validate_utf8,
         }
     }
 
     pub fn read(&mut self, output: &mut ViewBuffer, len: usize) -> 
Result<usize> {
-        // Here we convert `bytes::Bytes` into `arrow_buffer::Bytes`, which is 
zero copy
-        // Then we convert `arrow_buffer::Bytes` into `arrow_buffer:Buffer`, 
which is also zero copy
-        let buf = arrow_buffer::Buffer::from_bytes(self.buf.clone().into());
-        let block_id = output.append_block(buf);
+        // avoid creating a new buffer if the last buffer is the same as the 
current buffer
+        // This is especially useful when row-level filtering is applied, 
where we call lots of small `read` over the same buffer.
+        let need_to_create_new_buffer = {
+            if let Some(last_buffer) = output.buffers.last() {
+                !last_buffer.ptr_eq(&self.buf)
+            } else {
+                true
+            }
+        };
+
+        let block_id = if need_to_create_new_buffer {
+            output.append_block(self.buf.clone())
+        } else {
+            output.buffers.len() as u32 - 1
+        };

Review Comment:
   ```suggestion
           let block_id = {
               if output.buffers.last().is_some_and(|x| x.ptr_eq(&self.buf)) {
                   output.buffers.len() as u32 - 1
               } else {
                   output.append_block(self.buf.clone())
               }
           };
   ```
   
   Or something



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to