kosiew opened a new issue, #27885:
URL: https://github.com/apache/datafusion/issues/27885

   ## Related PR
   #27196 
   
   ## Problem
   
   `DFHeapSize` excludes the inline size of the value being measured: its owner 
adds that size when appropriate. The concrete Arrow array implementations in 
[`datafusion/common/src/heap_size.rs`](datafusion/common/src/heap_size.rs#L463) 
call `get_array_memory_size()` directly. Arrow includes the outer array object 
in that estimate. The generic `Arc<T>` implementation also adds 
`size_of::<T>()`, so measuring a `ScalarValue::Struct(Arc<StructArray>)` counts 
the `StructArray` object twice. The inline `Arc` pointer in the scalar slot is 
not the duplicate charge.
   
   This surfaced in the first revision of 
[#27196](https://github.com/apache/datafusion/pull/27196#discussion_r4731848688).
   
   ## Expected behavior
   
   - Measuring a bare concrete array excludes its own inline object but retains 
Arrow's estimate of its children and buffers.
   - Measuring an `Arc`-backed array adds the outer object and `Arc` refcounts 
once. Measuring a clone of that same `Arc` in the same `DFHeapSizeCtx` adds 
zero.
   - Distinct array objects can share buffers, such as after slicing. `Arc` 
identity alone does not deduplicate those buffers; this fix does not promise 
allocator-exact accounting.
   
   ## Proposed fix
   
   Fix the concrete array implementations in `heap_size.rs`, where Arrow's 
inclusive estimate enters the `DFHeapSize` traversal. Verify that each 
supported Arrow type (`StructArray`, list and list-view variants, 
`FixedSizeListArray`, and `MapArray`) includes `size_of::<Self>()` in 
`get_array_memory_size()`, then subtract that outer size in the shared 
implementation. Keep generic `Arc<T>` accounting and `ScalarValue::size()` 
unchanged. Review existing consumers of scalar estimates, including cached 
statistics and interval bounds, for assumptions about the old totals.
   
   Out of scope: migrating partial group clustering or other callers, changing 
memory-pool policy, and deduplicating shared Arrow buffers across distinct 
array objects.
   
   ## Acceptance criteria and verification
   
   - [ ] Add an exact-size regression with a nonempty `StructArray`: the bare 
array reports `get_array_memory_size() - size_of::<StructArray>()`; both 
`Arc<StructArray>` and a `ScalarValue::Struct` wrapping it report 
`get_array_memory_size() + 2 * size_of::<usize>()` when measured separately 
with fresh contexts. The old code overcounts each by `size_of::<StructArray>()`.
   - [ ] In one context, measure the struct scalar and a second scalar 
referencing the same `Arc`; the second contributes zero heap bytes. Add a list 
or map case to exercise a different nested layout.
   - [ ] Run `cargo test -p datafusion-common heap_size` and targeted tests for 
any downstream consumer whose expected estimate changes. Leave #27196's 
sort-key accounting unchanged.
   


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

Reply via email to