Repository navigation
Conversation
…compressor NonBlockedDecompressor#decompress(byte[], int, int) always routed through an intermediate off-heap outputBuffer, even though Parquet's own callers always request the entire decompressed page in one call. For large pages this extra buffer-to-buffer copy showed up clearly in profiling. Add an opt-in fast path: when the destination buffer can hold the whole decompressed page and the codec exposes a byte[]-to-byte[] API (Snappy does), decompress straight into the caller's array, skipping the off-heap outputBuffer and the copy out of it. Fixes apache#3987
|
Closing this PR. While following up on a regression this fast path caused (dictionary pages silently falling back to the slow path, which took several more commits to track down), I benchmarked the new byte[]-to-byte[] fast path against the original off-heap ByteBuffer path it replaces (JMH, 5 forks x 10 iterations):
The original path is faster at every size tested. Profiling with async-profiler explains why: the byte[]-to-byte[] JNI call (xerial snappy-java) requires Not pursuing this approach further - closing in favor of re-investigating with an approach that doesn't hit the array-pinning cost. |
Rationale
See #3987 for the full writeup. Summary:
NonBlockedDecompressor#decompress(byte[], int, int)always routes through an intermediate off-heapoutputBuffer, copying the decompressed bytes out into the caller's array afterwards. Parquet's own callers always request the whole decompressed page in one call, so that copy is never avoided — for pages holding large binary/string values it shows up clearly in profiling.Changes
NonBlockedDecompressor: add an opt-in fast path used when the caller's buffer can hold the whole decompressed page in one call. The codec copies the (typically much smaller) compressed bytes into a reusable heap scratch array and decompresses straight into the caller's destination array, skippingoutputBufferentirely. Gated behind a newsupportsDirectDecompress()hook (defaults tofalse, so behavior is unchanged for codecs that don't opt in).SnappyDecompressor: implements the new hooks viaorg.xerial.snappy.Snappy's existingbyte[]-to-byte[]API.TestSnappyCodec: new test covering a multi-MB payload through the fast path (and reuse across differently-sized pages, to exercise the scratch buffer growth), since the existing tests only use a few bytes.Testing
Ran
TestSnappyCodec,TestCompressionCodec,TestInteropReadLz4RawCodec(confirms LZ4-raw, which doesn't opt in, is unaffected), andTestParquetWriter(full Snappy round trip) — all pass.spotless:checkpasses.Microbenchmark decompressing a 1MB value through the real
CodecFactory-produced decompressor: ~190us/op before, ~134us/op after (~1.25x), consistent with the removedoutputBuffercopy.Note: I verified this change applies cleanly to current
masterand re-ran the above tests against a very recent commit before rebasing, but could not do a full local reactor build against the exact current tip because my localthrift(0.22.0) is older than whatparquet-format-structurescurrently requires (0.25.0) — the change itself doesn't touch anything thrift-generated, so I don't expect this to matter, but flagging it so CI is the source of truth here.Fixes #3987