Skip to content

fix: account for Arrow bytes map hash table allocations - #24229

Open
Boulea7 wants to merge 1 commit into
apache:mainfrom
Boulea7:fix/bytes-map-allocation-accounting
Open

fix: account for Arrow bytes map hash table allocations#24229
Boulea7 wants to merge 1 commit into
apache:mainfrom
Boulea7:fix/bytes-map-allocation-accounting

Conversation

@Boulea7

@Boulea7 Boulea7 commented Aug 10, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

ArrowBytesMap::size() and ArrowBytesViewMap::size() undercount memory because their hash tables are preallocated, while map_size starts at zero. This makes aggregate memory accounting inaccurate before the first resize and can also leave it out of sync after table growth.

What changes are included in this PR?

  • Initialize map_size from the hash table's allocation_size() in both constructors.
  • After an insertion changes the table capacity, resynchronize map_size from allocation_size() so exact allocation accounting is not mixed with incremental capacity estimates.
  • Use the same insertion path throughout both map implementations.
  • Add regression coverage for construction, capacity growth, populated take(), and the reset map returned by take().

Are these changes tested?

Yes.

  • cargo test -p datafusion-physical-expr-common — 77 unit tests and 8 doc tests passed.
  • cargo fmt --all -- --check — passed.
  • Workspace cargo clippy --all-targets --all-features -- -D warnings — passed.
  • ./dev/rust_lint.sh — passed, including the workspace lint, formatting, documentation, license, typo, and workflow checks.

I also ran the repository's extended workspace test command. It completed with 1,084 passed, 2 failed, and 1 ignored. Both failures were process RSS ceiling checks: the sort check used about 207 MB against a 190.7 MB limit, and the sort-merge join check initially used about 153.9 MB against a 152.6 MB limit. The sort-merge join check passed when rerun in isolation; an independent rerun reproduced only the sort RSS failure at about 206 MB. These checks exercise process-level integer sort and sort-merge join memory limits and do not execute the modified Arrow byte map paths, so the remaining failure appears environment-dependent.

Are there any user-facing changes?

There are no API changes. Memory estimates reported by these two byte maps now include the hash table allocation at construction and remain synchronized after growth and take().

AI-assisted contribution disclosure

This contribution was assisted by OpenAI Codex. I manually reviewed the final diff end-to-end, including the constructor, growth, and take() paths, and I understand and can explain the implementation. There are no known unresolved assumptions or unreviewed generated sections. The commit message records Generated-by: OpenAI Codex.

Initialize ArrowBytesMap and ArrowBytesViewMap accounting from the hash table allocation, and resynchronize it after table growth. Add regression coverage for construction, resize, and take.

Fixes apache#21248

Generated-by: OpenAI Codex
@github-actions github-actions Bot added the physical-expr Changes to the physical-expr crates label Aug 10, 2026
@Boulea7
Boulea7 force-pushed the fix/bytes-map-allocation-accounting branch from 34c109e to 30a98a8 Compare August 10, 2026 16:07

@alamb alamb 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.

Thanks @Boulea7 for the contribution


// `insert_accounted` estimates growth from capacity. Keep `map_size`
// consistent with the exact allocation recorded by `new` after a resize.
if map.capacity() != capacity {

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.

I think I missed how does map_size get report in the overall size? I expected to see a change in size() as well 🤔


#[test]
fn test_size_includes_hash_table_allocation() {
fn allocated_size(map: &ArrowBytesMap<i32, ()>) -> usize {

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.

This isn't testing any public API 🤔

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

Labels

physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrowBytesMap and ArrowBytesViewMap undercount memory by not accounting for initial hash table allocation

2 participants