You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2026/08/12 21:24:32 UTC

[I] Significant overhead in datafusion_common::utils::memory::get_record_batch_memory_size [datafusion]

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

   ### Describe the bug
   
   While profiling with this command (as part of testing out https://github.com/apache/datafusion/pull/24035)
   
   
   I noticed a non trivial amount of time (1% of query) is now spent measuring the memory used in `get_record_batch_memory_size`
   
   <img width="1880" height="994" alt="Image" src="https://github.com/user-attachments/assets/fa0a03dd-048e-40f2-bab5-e49152174467" />
   
   There are at least two memory allocations (for each record batch for each poll for each operator) that add up:
   1. calling Array::to_data() allocates a vec (for buffers): https://github.com/apache/datafusion/blob/d428760d709a375f3d997c84e9c4748a22584149/datafusion/common/src/utils/memory.rs#L170-L169
   2. Creating  a  counted buffer hash table: https://github.com/apache/datafusion/blob/d428760d709a375f3d997c84e9c4748a22584149/datafusion/common/src/utils/memory.rs#L154-L153
   
   ### To Reproduce
   
   ```shell
   cargo bench --profile=profiling --bench window_query_sql -- "window empty over, aggregate functions"
   ```
   
   And then run samply something like 
   
   ```shell
   samply record target/profiling/deps/window_query_sql-950028bf4c5b086c --bench "window empty over, aggregate functions"
   ```
   
   
   ### Expected behavior
   
   I expect memory accounting to be faster:
   1. Not allocate vec's 
   2. Likely not hash either
   
   I think the overhead is relatively small but since this is called on basically every operator work we could o
   
   ### Additional context
   
   It looks like it was most recently modified as part of this PR from @jordepic and @2010YOUY01 : 
   - #22862
   
   But the problematic allocations existed before that


-- 
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: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Significant overhead in datafusion_common::utils::memory::get_record_batch_memory_size [datafusion]

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on issue #24310:
URL: https://github.com/apache/datafusion/issues/24310#issuecomment-5275466304

   If those places have noticeable overhead, this PR might have similar issue 🤔 
   - https://github.com/apache/datafusion/pull/23777


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Significant overhead in datafusion_common::utils::memory::get_record_batch_memory_size [datafusion]

Posted by "jordepic (via GitHub)" <gi...@apache.org>.
jordepic commented on issue #24310:
URL: https://github.com/apache/datafusion/issues/24310#issuecomment-5296101698

   Thank you for the catch @alamb !


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Significant overhead in datafusion_common::utils::memory::get_record_batch_memory_size [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #24310:
URL: https://github.com/apache/datafusion/issues/24310#issuecomment-5295750882

   I think @ryux1 's PR in https://github.com/apache/datafusion/pull/24319 helps significantly 🏆 


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Significant overhead in datafusion_common::utils::memory::get_record_batch_memory_size [datafusion]

Posted by "ryux1 (via GitHub)" <gi...@apache.org>.
ryux1 commented on issue #24310:
URL: https://github.com/apache/datafusion/issues/24310#issuecomment-5302559258

   The follow-up review work is now implemented in #24319 at b6414cd88, rebased onto current `main`.
   
   In addition to the original allocation reduction, the PR now has no panic-based array-dispatch path, includes concrete byte/list-view parity coverage, and benchmarks the shared-buffer hash-join pattern by reusing one counter across 32 zero-copy slices. Against current `main`, that shared-slice case measures 6.75x / 5.45x / 5.37x faster at 4 / 16 / 64 columns respectively on the same machine.
   
   All review threads have been answered and resolved; CI has restarted on the rebased head.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Significant overhead in datafusion_common::utils::memory::get_record_batch_memory_size [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #24310: Significant overhead in datafusion_common::utils::memory::get_record_batch_memory_size
URL: https://github.com/apache/datafusion/issues/24310


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Significant overhead in datafusion_common::utils::memory::get_record_batch_memory_size [datafusion]

Posted by "ryux1 (via GitHub)" <gi...@apache.org>.
ryux1 commented on issue #24310:
URL: https://github.com/apache/datafusion/issues/24310#issuecomment-5274447253

   take


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org