etseidl commented on code in PR #8898:
URL: https://github.com/apache/arrow-rs/pull/8898#discussion_r2547814034


##########
parquet/src/file/metadata/memory.rs:
##########
@@ -95,21 +95,16 @@ impl<K: HeapSize, V: HeapSize> HeapSize for HashMap<K, V> {
 
 impl<T: HeapSize> HeapSize for Arc<T> {
     fn heap_size(&self) -> usize {
-        // Arc stores weak and strong counts on the heap alongside an instance 
of T
-        2 * std::mem::size_of::<usize>() + std::mem::size_of::<T>() + 
self.as_ref().heap_size()
-    }
-}
-
-impl HeapSize for Arc<dyn HeapSize> {
-    fn heap_size(&self) -> usize {
-        2 * std::mem::size_of::<usize>()
-            + std::mem::size_of_val(self.as_ref())
-            + self.as_ref().heap_size()
+        // Do not count the size of the Arc itself that is accounted for by the
+        // caller (the object that contains the Arc).
+        std::mem::size_of::<T>() + self.as_ref().heap_size()

Review Comment:
   from `Box::new`
   ```rust
     let x: Box<_> = Box::new(ArcInner {
         strong: atomic::AtomicUsize::new(1),
         weak: atomic::AtomicUsize::new(1),
         data,
     });
   ```
   `strong` and `weak` are also on the heap, along with the `T` data.
   
   `size_of::<Arc<_>>` returns 8, which is what I believe is accounted for in 
the size of the containers.



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