GH-3493: Optimize PlainValuesReader with direct ByteBuffer reads and batch methods#3560
Open
iemejia wants to merge 2 commits into
Open
GH-3493: Optimize PlainValuesReader with direct ByteBuffer reads and batch methods#3560iemejia wants to merge 2 commits into
iemejia wants to merge 2 commits into
Conversation
Replace the LittleEndianDataInputStream wrapper with direct ByteBuffer
access using LITTLE_ENDIAN byte order in PlainValuesReader. Each
read{Integer,Long,Float,Double}() previously dispatched through 4
in.read() calls per value and assembled the result with manual bit
shifts; it now compiles to a single ByteBuffer get*() JVM intrinsic.
In initFromPage, the page data is obtained as a single contiguous
ByteBuffer via ByteBufferInputStream.slice(available). The
ByteBufferInputStream.slice() method handles both single-buffer
(zero-copy view) and multi-buffer (copy into contiguous buffer) cases
transparently. In practice page data is almost always a single
contiguous buffer.
Benchmark (IntEncodingBenchmark.decodePlain, 100k INT32 values per
invocation, JMH -wi 3 -i 5 -f 1):
Pattern Before (ops/s) After (ops/s) Speedup
SEQUENTIAL 427,630,411 5,397,298,681 12.6x
RANDOM 431,052,072 5,437,926,758 12.6x
LOW_CARDINALITY 423,443,685 5,477,810,011 12.9x
HIGH_CARDINALITY 426,405,891 5,485,493,740 12.9x
The improvement is consistent regardless of data distribution because
the bottleneck was entirely in the dispatch overhead. All four numeric
plain reader types (int, long, float, double) benefit equally.
All 573 parquet-column tests pass.
… reads Add readIntegers/readFloats/readLongs/readDoubles batch methods to all PlainValuesReader inner classes. All four types use bulk typed-buffer view reads (e.g. buffer.asIntBuffer().get(dest, offset, count)) which bypass per-value bounds checks and position updates. Benchmark results (PlainDecodingBenchmark, 100K values, pre-allocated arrays): Type Per-value (ops/s) Batch (ops/s) Speedup INT32 5,454M 28,256M +418% FLOAT 5,407M 25,798M +377% INT64 5,408M 8,088M +50% DOUBLE 7,404M 7,965M +8%
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.
Summary
LittleEndianDataInputStreamwrapper with directByteBufferreads usingLITTLE_ENDIANbyte order inPlainValuesReader, eliminating per-value virtual dispatch overhead (4in.read()calls + manual bit shifts → singleByteBuffer.get*()JVM intrinsic).readIntegers,readFloats,readLongs,readDoubles) that use bulk typed-buffer view reads (e.g.buffer.asIntBuffer().get(dest, offset, count)) to bypass per-value bounds checks and position updates.ByteBufferviaByteBufferInputStream.slice(available), which handles both single-buffer (zero-copy view) and multi-buffer (copy into contiguous buffer) cases transparently.Benchmark Results
Per-value read optimization (100k INT32 values, JMH):
Batch read methods (PlainDecodingBenchmark, 100K values, pre-allocated arrays):
All 573 parquet-column tests pass.