maxburke commented on code in PR #9016:
URL: https://github.com/apache/arrow-rs/pull/9016#discussion_r2635984476


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -885,8 +896,11 @@ impl<T: ByteViewType + ?Sized> Array for 
GenericByteViewArray<T> {
 
     fn shrink_to_fit(&mut self) {
         self.views.shrink_to_fit();
-        self.buffers.iter_mut().for_each(|b| b.shrink_to_fit());
-        self.buffers.shrink_to_fit();
+
+        if let Some(buffers) = Arc::get_mut(&mut self.buffers) {

Review Comment:
   So the issue I have with `Arc::make_mut` is that if I slice array I now have 
two references to the underlying buffers. If I call `shrink_to_fit` on one of 
them, `Arc::make_mut` will clone the buffers and then `shrink_to_fit` will be 
called on one of them. But because the underlying buffers end up being cloned, 
it doesn't make the original allocation shrink and in the end it'll end up 
using more memory, until the other reference is dropped.
   
   Additionally it'll create more allocator pressure because the buffer cloning 
will duplicate the buffer at it's pre-shrunken size before it's shrunk.



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