[SPARK-56897][SQL] Reduce per-value allocations in DELTA_BYTE_ARRAY Parquet decoder#55924
Open
iemejia wants to merge 1 commit into
Open
[SPARK-56897][SQL] Reduce per-value allocations in DELTA_BYTE_ARRAY Parquet decoder#55924iemejia wants to merge 1 commit into
iemejia wants to merge 1 commit into
Conversation
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.
What changes were proposed in this pull request?
Reduces per-value heap allocations in
VectorizedDeltaByteArrayReader(the Parquet DELTA_BYTE_ARRAY vectorized decoder) by replacingByteBuffer-based state tracking with a reusablebyte[]buffer.Key changes:
Replace
ByteBuffer previouswithbyte[] prevBuf+int prevLen: The DELTA_BYTE_ARRAY encoding exploits prefix sharing between consecutive values. The old code materialized each decoded value as aByteBufferobtained fromarrayData.getByteBuffer()(which allocates ~48 bytes per value viaByteBuffer.wrap()). The new approach uses a reusablebyte[]buffer where the prefix bytes from the previous iteration are already in place at the start -- only the suffix portion needs to be written.Add
getSuffixInto()toVectorizedDeltaLengthByteArrayReader: New method that reads suffix bytes directly into a caller-suppliedbyte[]viaInputStream.read(), avoiding theByteBufferallocation thatgetBytes()/in.slice()performs. Also addsgetSuffixLength()for cases where only the length is needed.Rewrite
skipBinary()to useprevBufdirectly: The old implementation was particularly wasteful -- it maintained twoWritableColumnVectorinstances (binaryValVectorandtempBinaryValVector), reset one per skipped value, and swapped them after each iteration. The new implementation simply assembles intoprevBufwithout touching any column vectors.Remove
tempBinaryValVectorfield: No longer needed after theskipBinaryrewrite.Why are the changes needed?
The DELTA_BYTE_ARRAY decoder allocated 2
ByteBufferobjects per decoded value (one fromin.slice()for the suffix, one fromarrayData.getByteBuffer()for the previous-value reference). For a typical 4096-value page, this produced ~8K short-lived objects (~384KB) that stress the young-generation GC.The
skipBinarypath was even worse: it reset and rebuilt column vectors per skipped value, involvingreserve(),Arrays.copyOf(), andputArray()overhead just to maintain the previous-value state.After this change, the hot path performs zero per-value heap allocations (the
prevBufarray is reused across all values and only grows if a value exceeds its current capacity).Normalized benchmark improvements (using Variant reads as cross-hardware baseline):
readBinary: 1.1-1.3x faster across overlap shapesskipBinary: 1.5-1.9x faster (largest gains from eliminating column vector reset/swap)readBinary(len)single-value: ~1.2x fasterDoes this PR introduce any user-facing change?
No.
How was this patch tested?
ParquetDeltaByteArrayEncodingSuite(14 tests),ParquetDeltaLengthByteArrayEncodingSuite,ParquetEncodingSuite-- all pass.VectorizedDeltaReaderBenchmarkGroup C (DELTA_BYTE_ARRAY) with four overlap shapes (no overlap, half overlap, full overlap, len=64).Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenCode with Claude Opus (claude-opus-4.6)