You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@parquet.apache.org by "arouel (via GitHub)" <gi...@apache.org> on 2026/04/06 19:09:26 UTC
[PR] GH-3466 Improve `RunLengthBitPackingHybridDecoder.readNext` to avoid per-call buffer allocation and `DataInputStream` wrapping [parquet-java]
arouel opened a new pull request, #3467:
URL: https://github.com/apache/parquet-java/pull/3467
### Rationale for this change
`RunLengthBitPackingHybridDecoder.readNext()` allocates a new `int[]` and `byte[]` on every PACKED-mode call. The existing code even acknowledges this with a `// TODO: reuse a buffer` comment 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:
1. **Per-call buffer allocation.** `currentBuffer = new int[currentCount]` and `byte[] bytes = new byte[numGroups * bitWidth]` are allocated fresh on every PACKED-mode `readNext()`. 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.
2. **Per-call `DataInputStream` wrapping.** `new DataInputStream(in).readFully(bytes, 0, bytesToRead)` creates a wrapper object on every PACKED-mode call just to access `readFully()`.
### What changes are included in this PR?
Three changes to `RunLengthBitPackingHybridDecoder`:
- **`currentBuffer` promoted from local to field**, reused across `readNext()` calls with a grow-only strategy, only reallocated when the next run requires a larger buffer than currently held.
- **`byte[] bytes` promoted to a field `packedBytes`**, same grow-only reuse strategy.
- **`new DataInputStream(in).readFully(...)` replaced with a private `readFully()` method** that reads directly from the underlying `InputStream`, 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):
| Metric | Before | After | Change |
|---|---|---|---|
| Throughput | 44.2 s/op | 42.5 s/op | **-3.6%** |
| Allocation rate | 908.9 MB/s | 793.9 MB/s | **-12.7%** |
| Allocation per op | 42.1 GB | 35.4 GB | **-15.8%** |
| RLE decoder alloc samples | 2,402 (18.9%) | 146 (1.2%) | **-93.9%** |
| RLE decoder alloc bytes | ~7,245 MB | ~417 MB | **-94.2%** |
### Are these changes tested?
Yes. Existing tests for `RunLengthBitPackingHybridDecoder` (e.g. `TestRunLengthBitPackingHybridEncoder`) cover round-trip correctness for both RLE and PACKED modes across various bit widths. No new tests are needed since the change is purely a performance optimization. The decoded values are identical, only the buffer lifecycle changes from allocate-per-call to reuse-and-grow.
### 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
--
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: issues-unsubscribe@parquet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org
Re: [PR] GH-3466: Improve `RunLengthBitPackingHybridDecoder.readNext` to avoid per-call buffer allocation and `DataInputStream` wrapping [parquet-java]
Posted by "arouel (via GitHub)" <gi...@apache.org>.
arouel commented on PR #3467:
URL: https://github.com/apache/parquet-java/pull/3467#issuecomment-4720904972
> I've left one fix that addresses a concern is that `currentBuffer` retains stale values from a previous larger packed run in positions beyond `currentCount`. While those positions are never accessed today (the indexing is bounded by `currentBufferLength`), it's a latent risk. Let's add defensive zeroing, consistent with how packedBytes is zeroed on short reads.
Thank you for the review. I applied the code changes as suggested.
--
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: issues-unsubscribe@parquet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org
Re: [PR] GH-3466: Improve `RunLengthBitPackingHybridDecoder.readNext` to avoid per-call buffer allocation and `DataInputStream` wrapping [parquet-java]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #3467:
URL: https://github.com/apache/parquet-java/pull/3467#issuecomment-5574591322
@arouel Could you pull in latest main?
--
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: issues-unsubscribe@parquet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org
Re: [PR] GH-3466: Improve `RunLengthBitPackingHybridDecoder.readNext` to avoid per-call buffer allocation and `DataInputStream` wrapping [parquet-java]
Posted by "arouel (via GitHub)" <gi...@apache.org>.
arouel commented on PR #3467:
URL: https://github.com/apache/parquet-java/pull/3467#issuecomment-6522860677
@Fokko I pulled in the latest master and migrated the test case
--
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: issues-unsubscribe@parquet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org
Re: [PR] GH-3466: Improve `RunLengthBitPackingHybridDecoder.readNext` to avoid per-call buffer allocation and `DataInputStream` wrapping [parquet-java]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #3467:
URL: https://github.com/apache/parquet-java/pull/3467#discussion_r3156610081
##########
parquet-column/src/main/java/org/apache/parquet/column/values/rle/RunLengthBitPackingHybridDecoder.java:
##########
@@ -90,17 +92,23 @@ private void readNext() throws IOException {
case PACKED:
int numGroups = header >>> 1;
currentCount = numGroups * 8;
+ currentBufferLength = currentCount;
LOG.debug("reading {} values BIT PACKED", currentCount);
- currentBuffer = new int[currentCount]; // TODO: reuse a buffer
- byte[] bytes = new byte[numGroups * bitWidth];
- // At the end of the file RLE data though, there might not be that many bytes left.
- int bytesToRead = (int) Math.ceil(currentCount * bitWidth / 8.0);
- bytesToRead = Math.min(bytesToRead, in.available());
- new DataInputStream(in).readFully(bytes, 0, bytesToRead);
+ if (currentBuffer == null || currentBuffer.length < currentCount) {
+ currentBuffer = new int[currentCount];
+ }
+ int bytesNeeded = numGroups * bitWidth;
+ if (packedBytes == null || packedBytes.length < bytesNeeded) {
+ packedBytes = new byte[bytesNeeded];
+ }
+ int bytesRead = in.readNBytes(packedBytes, 0, bytesNeeded);
Review Comment:
Nice, now we're at Java 11 :)
--
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: issues-unsubscribe@parquet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org
Re: [PR] GH-3466: Improve `RunLengthBitPackingHybridDecoder.readNext` to avoid per-call buffer allocation and `DataInputStream` wrapping [parquet-java]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #3467:
URL: https://github.com/apache/parquet-java/pull/3467#discussion_r3156613757
##########
parquet-column/src/main/java/org/apache/parquet/column/values/rle/RunLengthBitPackingHybridDecoder.java:
##########
@@ -90,17 +92,23 @@ private void readNext() throws IOException {
case PACKED:
int numGroups = header >>> 1;
currentCount = numGroups * 8;
+ currentBufferLength = currentCount;
LOG.debug("reading {} values BIT PACKED", currentCount);
- currentBuffer = new int[currentCount]; // TODO: reuse a buffer
- byte[] bytes = new byte[numGroups * bitWidth];
- // At the end of the file RLE data though, there might not be that many bytes left.
- int bytesToRead = (int) Math.ceil(currentCount * bitWidth / 8.0);
- bytesToRead = Math.min(bytesToRead, in.available());
- new DataInputStream(in).readFully(bytes, 0, bytesToRead);
+ if (currentBuffer == null || currentBuffer.length < currentCount) {
+ currentBuffer = new int[currentCount];
+ }
Review Comment:
```suggestion
} else {
Arrays.fill(currentBuffer, currentCount, currentBuffer.length, 0);
}
```
##########
parquet-column/src/main/java/org/apache/parquet/column/values/rle/RunLengthBitPackingHybridDecoder.java:
##########
@@ -90,17 +92,23 @@ private void readNext() throws IOException {
case PACKED:
int numGroups = header >>> 1;
currentCount = numGroups * 8;
+ currentBufferLength = currentCount;
LOG.debug("reading {} values BIT PACKED", currentCount);
- currentBuffer = new int[currentCount]; // TODO: reuse a buffer
- byte[] bytes = new byte[numGroups * bitWidth];
- // At the end of the file RLE data though, there might not be that many bytes left.
- int bytesToRead = (int) Math.ceil(currentCount * bitWidth / 8.0);
- bytesToRead = Math.min(bytesToRead, in.available());
- new DataInputStream(in).readFully(bytes, 0, bytesToRead);
+ if (currentBuffer == null || currentBuffer.length < currentCount) {
+ currentBuffer = new int[currentCount];
+ }
+ int bytesNeeded = numGroups * bitWidth;
+ if (packedBytes == null || packedBytes.length < bytesNeeded) {
+ packedBytes = new byte[bytesNeeded];
+ }
Review Comment:
```suggestion
} else {
Arrays.fill(packedBytes, bytesNeeded, packedBytes.length, (byte) 0);
}
```
--
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: issues-unsubscribe@parquet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@parquet.apache.org
For additional commands, e-mail: issues-help@parquet.apache.org