GH-3466 Improve RunLengthBitPackingHybridDecoder.readNext to avoid per-call buffer allocation and DataInputStream wrapping#3467
Open
arouel wants to merge 2 commits intoapache:masterfrom
Open
Conversation
…avoid per-call buffer allocation and `DataInputStream` wrapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
RunLengthBitPackingHybridDecoder.readNext()allocates a newint[]andbyte[]on every PACKED-mode call. The existing code even acknowledges this with a// TODO: reuse a buffercomment at line 94. In workloads that decode many bit-packed runs (definition levels, repetition levels, RLE-encoded integers), these allocations become a significant source of GC pressure.There are two issues:
Per-call buffer allocation.
currentBuffer = new int[currentCount]andbyte[] bytes = new byte[numGroups * bitWidth]are allocated fresh on every PACKED-modereadNext(). The individual allocations are modest (8–128 ints per run) but occur thousands of times per column chunk. In a custom JFR-profiled benchmark merging 60 Parquet files (180M rows, 10 columns), these two sites were the number 2 and number 6 allocation hotspots respectively: 2,402 out of 12,711 total allocation samples (18.9%), accounting for ~7.2 GB of allocation per operation.Per-call
DataInputStreamwrapping.new DataInputStream(in).readFully(bytes, 0, bytesToRead)creates a wrapper object on every PACKED-mode call just to accessreadFully().What changes are included in this PR?
Three changes to
RunLengthBitPackingHybridDecoder:currentBufferpromoted from local to field, reused acrossreadNext()calls with a grow-only strategy, only reallocated when the next run requires a larger buffer than currently held.byte[] bytespromoted to a fieldpackedBytes, same grow-only reuse strategy.new DataInputStream(in).readFully(...)replaced with a privatereadFully()method that reads directly from the underlyingInputStream, eliminating the per-call wrapper allocation and virtual dispatch.Custom JFR-profiled benchmark results (merge of 60 Parquet files, 180M rows, 10 columns, JDK 26, macOS aarch64):
Are these changes tested?
Yes, changes are tested. We added a regression test in
TestRunLengthBitPackingHybridEncodercalledtestTruncatedPackedRunAfterFullPackedRunDoesNotReuseStaleBytesto cover a truncated packed-run edge case after buffer reuse. We also ran the fullTestRunLengthBitPackingHybridEncoderclass andRunLengthBitPackingHybridIntegrationTestand all tests passed.Are there any user-facing changes?
No. This is a transparent performance improvement internal to the RLE decoder. Decoded values are identical. No API changes, no configuration changes, no behavioral changes.
Closes #3466