Skip to content

Fix ArrowBytesViewMap retained capacity accounting - #24257

Open
kosiew wants to merge 4 commits into
apache:mainfrom
kosiew:memcalc-02-23393
Open

Fix ArrowBytesViewMap retained capacity accounting#24257
kosiew wants to merge 4 commits into
apache:mainfrom
kosiew:memcalc-02-23393

Conversation

@kosiew

@kosiew kosiew commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

ArrowBytesViewMap::size() currently undercounts retained heap memory by accounting for used lengths rather than allocated capacities in some of its owned storage.

In particular, it does not account for unused capacity in views, the backing allocation of completed, or unused capacity retained by completed Arrow buffers. Since size() is used for memory accounting, it should report the heap allocations owned by the map while continuing to exclude self and external input-array buffers.

What changes are included in this PR?

  • Updates ArrowBytesViewMap::size() to account for the allocated capacity of views.
  • Accounts for the backing allocation of the completed vector and the retained capacity of each completed Buffer.
  • Uses allocation-based accounting for the in-progress buffer.
  • Clarifies that size() excludes both self and input-array buffers.
  • Adds DFHeapSize support for u128, allowing Vec<u128> capacity to be accounted for through the existing heap-size infrastructure.
  • Adds tests covering u128 and Vec<u128> heap-size accounting and retained-capacity accounting in ArrowBytesViewMap.

Are these changes tested?

Yes. The patch adds:

  • test_vec_u128, which verifies that a Vec<u128> is accounted for using its allocated capacity.
  • An additional u128 assertion in the existing zero-heap-size test.
  • test_size_counts_retained_buffer_capacities, which verifies that ArrowBytesViewMap::size() accounts for unused views capacity, the completed vector allocation, and retained completed-buffer capacity. It also verifies that reinserting duplicate values does not report additional owned storage.

Are there any user-facing changes?

No direct user-facing or API behavior changes. This corrects internal memory accounting for ArrowBytesViewMap.

LLM-generated code disclosure

This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed.

kosiew added 4 commits August 11, 2026 16:54
…pdate docs, and add regression test for flush-path capacity and duplicate-insert
…nual element sizing

- Completed counts of Vec descriptors and Buffer capacities.
- Added test to enforce slack handling, flush partial retained buffers, and verify duplicate retention size.
- Avoided empty‑size assertion by acknowledging HashTable preallocation.
…ion covering views slack, full completed Vec allocation, and buffer slack
… capacity unit test, and update ArrowBytesViewMap::views to use DFHeapSize
@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates common Related to common crate labels Aug 11, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.01%. Comparing base (a05388e) to head (5ce5c21).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #24257    +/-   ##
========================================
  Coverage   81.01%   81.01%            
========================================
  Files        1106     1106            
  Lines      383974   384106   +132     
  Branches   383974   384106   +132     
========================================
+ Hits       311085   311197   +112     
- Misses      54554    54567    +13     
- Partials    18335    18342     +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kosiew
kosiew marked this pull request as ready for review August 12, 2026 07:37
@kosiew
kosiew requested a review from comphead August 12, 2026 07:38

@neilconway neilconway left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're fixing this, I wonder if it is correct to initialize map_size to 0 when the initial map capacity is 512?

let completed_size: usize = self.completed.iter().map(|b| b.len()).sum();
// All fields below own their allocations. Count retained capacity rather
// than used length because this value drives memory accounting.
let views_size = self.views.heap_size(&mut DFHeapSizeCtx::default());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allocated_size should be equivalent here, I think (plus cheaper to compute).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants