GH-3530: Bypass Hadoop codec abstraction to optimize compression performance#3570
Open
iemejia wants to merge 1 commit into
Open
GH-3530: Bypass Hadoop codec abstraction to optimize compression performance#3570iemejia wants to merge 1 commit into
iemejia wants to merge 1 commit into
Conversation
…n performance Some of the Parquet compression codecs rely on Hadoop's CompressionCodec. After evaluating with performance tests that isolate the CPU utilization it is clear that the Hadoop abstraction introduces considerable overhead. This PR improves that for Snappy, LZ4_RAW, ZSTD, GZIP, LZO, and BROTLI. It also migrates Brotli from jbrotli to brotli4j. Bypass Hadoop CompressionCodec for Snappy (xerial JNI), LZ4_RAW (airlift), ZSTD (zstd-jni), GZIP (JDK), LZO (airlift), and BROTLI (brotli4j) in both CodecFactory and DirectCodecFactory, eliminating per-page codec pool lookups, stream wrapper allocation, and unnecessary buffer copies. ZSTD: replace streaming ZstdOutputStreamNoFinalizer/ZstdInputStreamNoFinalizer with reusable ZstdCompressCtx/ZstdDecompressCtx single-call APIs. GZIP: bypass Hadoop's GzipCodec and its codec-pool/stream-wrapper overhead with direct JDK GZIPOutputStream/GZIPInputStream. Compression level is read from the existing "zlib.compress.level" Hadoop configuration key. LZO: bypass the GPL-licensed com.hadoop.compression.lzo.LzoCodec entirely using aircompressor's LzoHadoopStreams (Apache 2.0). The framing format (big-endian length-prefixed blocks) is wire-compatible with Hadoop's LzoCodec, so existing LZO Parquet files remain readable. Removes the GPL dependency for LZO support. Uncomment previously disabled LZO benchmarks and tests. BROTLI: migrate from abandoned brotli-codec (jbrotli, 2016, x86-only) to brotli4j 1.23.0 (com.aayushatharva.brotli4j) which supports 10 platforms including linux/darwin/windows aarch64. brotli4j is a runtime-only optional dependency accessed via reflection (Encoder.compress and Decoder.decompress) to avoid a compile-time dependency. Uses Decoder.decompress(byte[], int, int) instead of DirectDecompress to avoid loading classes that reference Netty. Remove non-aarch64 Maven profile guards and aarch64 test skips. ByteBuffer decompressors use native APIs with slice + manual position advancement pattern (matching DirectCodecFactory.BaseDecompressor): - Snappy: Snappy.uncompress(slice, slice) - ZSTD: Zstd.decompress(slice, slice) - LZ4_RAW: decompressor.decompress(slice, slice) - GZIP: ByteBufferInputStream.wrap(slice) -> GZIPInputStream - LZO: ByteBufferInputStream.wrap(slice) -> LzoHadoopInputStream - BROTLI: byte[] copy through Decoder.decompress (no direct ByteBuffer API) Add BytesInput.toByteArray() zero-copy override in ByteArrayBytesInput. Add benchmarks: CompressionBenchmark, CpuReadBenchmark, CpuWriteBenchmark, FileReadBenchmark, FileWriteBenchmark, InMemoryInputFile, InMemoryOutputFile, ConcurrentReadWriteBenchmark. Remove encoding/row-group benchmarks. Add 15 new tests in TestDirectCodecFactory, 3 new tests in TestBytesInput.
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.
Part of #3530 — Apache Parquet Java Performance Improvements
Summary
Bypass the Hadoop
CompressionCodecabstraction for all six supported codecs, eliminating per-page codec-pool lookups, stream-wrapper allocation, and unnecessary buffer copies in bothCodecFactoryandDirectCodecFactory.SnappyCodecstream wrappersSnappy.compress/uncompressdirect callsLZ4Compressor/LZ4DecompressordirectZstdOutputStreamNoFinalizer/ZstdInputStreamNoFinalizerZstdCompressCtx/ZstdDecompressCtxsingle-call APIsGzipCodecwith codec-pool overheadGZIPOutputStream/GZIPInputStreamdirectcom.hadoop.compression.lzo.LzoCodecLzoHadoopStreams(Apache 2.0, wire-compatible)brotli-codec(jbrotli, 2016, x86-only)brotli4j1.23.0 (10 platforms incl. aarch64, reflection-loaded)Notable side effects:
JMH benchmarks:
CompressionBenchmark,CpuReadBenchmark,CpuWriteBenchmark,FileReadBenchmark,FileWriteBenchmark,ConcurrentReadWriteBenchmark.Benchmark results
Environment: JDK 25.0.3 (Temurin), OpenJDK 64-Bit Server VM, JMH 1.37, Linux x86_64.
End-to-end file write (100K rows, SingleShotTime, ms/op lower is better):
End-to-end file read (ms/op lower is better):
Raw codec throughput (
DirectCodecFactory): Snappy/ZSTD/LZ4/GZIP unchanged (already had native access). Brotli decompression improved 2.3-2.7x (brotli4j >> jbrotli).V2 shows consistently larger speedups than V1 because V2 encoding produces more, smaller pages, meaning more codec invocations per file where the per-invocation Hadoop overhead accumulates.