Skip to content

GH-1038: Trim object memory for ArrowBuf - #1044

Merged
jbonofre merged 4 commits into
apache:mainfrom
lriggs:arrowBufMemory
Mar 4, 2026
Merged

GH-1038: Trim object memory for ArrowBuf#1044
jbonofre merged 4 commits into
apache:mainfrom
lriggs:arrowBufMemory

Conversation

@lriggs

Copy link
Copy Markdown
Contributor

What's Changed

A significant number of ArrowBuf and BufferLedger objects are created during certain workloads. Saving several bytes per instance could add up to significant memory savings and reduced memory allocation expense and garbage collection.

The id field, which was a sequential value used when logging object information, is replaced with an identity hash code. This should still allow enough information for debugging without the memory overhead. There may be possible duplicate values but it shouldn't matter for logging purposes.

Atomic fields can be replaced by a primitive and a static updater which saves several bytes per instance.

ArrowBuf

ComponentBeforeAfterSavings
idGenerator (static)AtomicLongRemoved24 bytes globally
id field (per instance)long (8 bytes)Removed8 bytes per instance
getId()Returns id fieldReturns System.identityHashCode(this)

BufferLedger

ComponentBeforeAfterSavings
LEDGER_ID_GENERATOR (static)AtomicLongRemoved24 bytes globally
ledgerId (per instance)long (8 bytes)Removed8 bytes per instance
bufRefCntAtomicInteger (24 bytes)volatile int + static updater20 bytes per instance

Total Savings

ScaleArrowBufBufferLedgerCombined
100K800 KB2.8 MB~3.6 MB
1M8 MB28 MB~36 MB
10M80 MB280 MB~360 MB

Benchmarking

I ran the added benchmark before and after the metadata trimming.

Metadata Trimmed

BenchmarkModeScoreErrorUnits
MemoryFootprintBenchmarks.measureAllocationPerformanceavgt456.831± 36.059us/op
MemoryFootprintBenchmarks.measureArrowBufMemoryFootprintss161.085± 35.596ms/op
Created 100000 ArrowBuf instances. Heap memory usedsum35631520 bytes (33.98 MB)0bytes
Average memory per ArrowBufsum356.32 bytes0bytes

Previous Object Layout

BenchmarkModeScoreErrorUnits
MemoryFootprintBenchmarks.measureAllocationPerformanceavgt466.171± 16.233us/op
MemoryFootprintBenchmarks.measureArrowBufMemoryFootprintss176.790± 17.943ms/op
Created 100000 ArrowBuf instances. Heap memory usedsum38817480 bytes (37.02 MB)0bytes
Average memory per ArrowBufsum388.17 bytes0bytes

Closes#1038.

@lriggslriggs changed the title GH-1038 Trim object memory for ArrowBufGH-1038: Trim object memory for ArrowBufMar 2, 2026
@github-actions

This comment has been minimized.

@lriggs

Copy link
Copy Markdown
ContributorAuthor

I dont seem to have permission to add the label.

@lidavidmlidavidm added the enhancement PRs that add or improve features. label Mar 3, 2026
@github-actionsgithub-actionsBot added this to the 19.0.0 milestone Mar 3, 2026
@jbonofre
jbonofre merged commit 5dfd259 into apache:mainMar 4, 2026
26 of 29 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementPRs that add or improve features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trim object memory for ArrowBuf

4 participants

@lriggs@jbonofre@lidavidm@laurentgo