lyang24 opened a new pull request, #9282:
URL: https://github.com/apache/arrow-rs/pull/9282

   # Which issue does this PR close?
   
   small optimization
   
   # Rationale for this change
   key insight is the byte clone is cheap just a ref count compare to vec clone 
is a alloc + memcopy.
   
   before
   ```
   let mut result = Vec::new();          // alloc #1
   result.extend_from_slice(prefix);
   result.extend_from_slice(suffix);
   
   let data = Bytes::from(result.clone()); // alloc #2 + memcpy
   item.set_from_bytes(data);
   self.previous_value = result;          // keep Vec
   ```
   
   after
   ```
   let mut result = Vec::with_capacity(prefix_len + suffix.len()); // alloc #1
   result.extend_from_slice(&self.previous_value[..prefix_len]);
   result.extend_from_slice(suffix);
   
   let data = Bytes::from(result);       // no alloc, takes Vec buffer
   item.set_from_bytes(data.clone());    // cheap refcount bump
   self.previous_value = data;           // move, no alloc
   ```
   
   # What changes are included in this PR?
   previous_value type changed to Bytes
   preallocate result vec capacity.
   
   # Are these changes tested?
   
   the existing test should pass
   
   # Are there any user-facing changes?
   
   no
   


-- 
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