kosiew commented on code in PR #22358:
URL: https://github.com/apache/datafusion/pull/22358#discussion_r3273538730
##########
datafusion/common/src/heap_size.rs:
##########
@@ -558,4 +589,173 @@ mod tests {
assert_eq!(heap_size, heap_size_with_clones);
}
+
+ #[test]
+ fn test_arc_dyn() {
+ let a1: Arc<dyn DFHeapSize> = Arc::new(String::from("hello"));
+ let baseline = size(&a1);
+
+ let a2 = Arc::clone(&a1);
+ let mut ctx = DFHeapSizeCtx::default();
+ let with_clones = a1.heap_size(&mut ctx) + a2.heap_size(&mut ctx);
+ assert_eq!(baseline, with_clones);
+ }
+
+ #[test]
+ fn test_primitives() {
+ assert_eq!(size(&true), 0);
+ assert_eq!(size(&0u8), 0);
+ assert_eq!(size(&0u16), 0);
+ assert_eq!(size(&0u32), 0);
+ assert_eq!(size(&0u64), 0);
+ assert_eq!(size(&0usize), 0);
+ assert_eq!(size(&0i8), 0);
+ assert_eq!(size(&0i16), 0);
+ assert_eq!(size(&0i32), 0);
+ assert_eq!(size(&0i64), 0);
+ assert_eq!(size(&0i128), 0);
+ assert_eq!(size(&i256::ZERO), 0);
+ assert_eq!(size(&0f32), 0);
+ assert_eq!(size(&0f64), 0);
+ assert_eq!(size(&f16::from_f32(0.0)), 0);
+ }
+
+ #[test]
+ fn test_string() {
+ let mut s = String::with_capacity(32);
+ s.push_str("hello");
+ assert_eq!(size(&s), 32);
+
+ let empty = String::new();
+ assert_eq!(size(&empty), 0);
+ }
+
+ #[test]
+ fn test_str() {
+ let s: &str = "hello";
Review Comment:
I think this test is enforcing behavior that conflicts with the invariant
described in the new module docs. The docs define HeapSize as the number of
bytes a value owns on the heap, but `\"hello\"` here is a string literal stored
in static memory, so the borrowed `&str` does not actually own a heap
allocation.
Could we either avoid testing `&str` as an owned heap value, or clarify in
the docs that the `str` impl is intended as an internal accounting helper for
owners like `Arc<str>` and test that ownership path instead?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]