Skip to content

GH-3530: Bypass Hadoop codec abstraction to optimize compression performance#3570

Open
iemejia wants to merge 14 commits into
apache:masterfrom
iemejia:parquet-perf-v2-par6-compression
Open

GH-3530: Bypass Hadoop codec abstraction to optimize compression performance#3570
iemejia wants to merge 14 commits into
apache:masterfrom
iemejia:parquet-perf-v2-par6-compression

Conversation

@iemejia

@iemejia iemejia commented May 17, 2026

Copy link
Copy Markdown
Member

Part of #3530 — Apache Parquet Java Performance Improvements

Summary

Bypass the Hadoop CompressionCodec abstraction for all six supported codecs, eliminating per-page codec-pool lookups, stream-wrapper allocation, and unnecessary buffer copies in both CodecFactory and DirectCodecFactory.

Codec Before After
Snappy Hadoop SnappyCodec stream wrappers xerial Snappy.compress/uncompress direct calls
LZ4_RAW Hadoop codec abstraction airlift LZ4Compressor/LZ4Decompressor direct
ZSTD Streaming ZstdOutputStreamNoFinalizer/ZstdInputStreamNoFinalizer Reusable ZstdCompressCtx/ZstdDecompressCtx single-call APIs
GZIP Hadoop GzipCodec with codec-pool overhead JDK GZIPOutputStream/GZIPInputStream direct
LZO GPL com.hadoop.compression.lzo.LzoCodec aircompressor LzoHadoopStreams (Apache 2.0, wire-compatible)
Brotli Abandoned brotli-codec (jbrotli, 2016, x86-only) brotli4j 1.23.0 (10 platforms incl. aarch64, reflection-loaded)

Notable side effects:

  • LZO: Removes GPL dependency; uses Apache 2.0 aircompressor. Wire-compatible framing.
  • Brotli: Enables aarch64 support (linux, macOS, Windows). Removes non-aarch64 Maven profile guards and test skips.

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):

Codec V1 dict=true V2 dict=true V2 Speedup
SNAPPY 50.6 -> 40.9 (1.24x) 69.7 -> 38.7 1.80x
ZSTD 52.3 -> 43.6 (1.20x) 70.7 -> 40.6 1.74x
LZ4_RAW 49.6 -> 41.3 (1.20x) 70.2 -> 39.0 1.80x
GZIP 149.9 -> 119.3 (1.26x) 123.4 -> 67.6 1.83x
BROTLI 55.4 -> 46.8 (1.18x) 72.8 -> 41.8 1.74x

End-to-end file read (ms/op lower is better):

Codec V1 Speedup V2 Speedup
SNAPPY 1.50x 1.61x
ZSTD 1.49x 1.60x
LZ4_RAW 1.23x 1.57x
GZIP 1.47x 1.49x
BROTLI 1.83x 1.91x

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.

iemejia added 10 commits July 11, 2026 07:49
…n performance

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.

SNAPPY: direct byte-array JNI calls via Snappy.compress/uncompress, avoiding
the Hadoop stream abstraction and intermediate direct ByteBuffer copies.

ZSTD: replace streaming ZstdOutputStreamNoFinalizer/ZstdInputStreamNoFinalizer
with reusable ZstdCompressCtx/ZstdDecompressCtx single-call APIs. Supports
compression level and multi-threaded workers configuration.

LZ4_RAW: direct airlift Lz4Compressor/Lz4Decompressor with reusable direct
ByteBuffers, bypassing Hadoop's NonBlockedCompressor overhead.

GZIP: bypass Hadoop's GzipCodec and codec-pool/stream-wrapper overhead with
direct JDK GZIPOutputStream/GZIPInputStream. Compression level is read from
the existing "zlib.compress.level" Hadoop configuration key.

LZO: use aircompressor's LzoHadoopStreams directly, bypassing the GPL-licensed
com.hadoop.compression.lzo.LzoCodec. Wire-compatible with Hadoop's LzoCodec.

BROTLI: migrate from jbrotli (unmaintained) to brotli4j via reflection,
using single-call Encoder.compress/Decoder.decompress byte-array APIs.

End-to-end interop tests (TestCompressionInterop) validate that files written
with the old Hadoop CompressionCodec path are readable by the new direct path
and vice versa, for all 6 codecs including multi-row-group scenarios.
Remove the legacy Hadoop CompressionCodec-based compression/decompression
path from CodecFactory and DirectCodecFactory. All codecs now use only the
optimized direct implementations (snappy-java, zstd-jni, airlift LZ4/LZO,
JDK GZIP, brotli4j) introduced in the previous commit.

Removed from CodecFactory:
- HeapBytesCompressor/HeapBytesDecompressor (Hadoop stream wrappers)
- getCodec() method (Hadoop codec loading via reflection)
- CODEC_BY_NAME static cache and cacheKey() helper
- Hadoop codec fallback in createCompressor()/createDecompressor()

Removed from DirectCodecFactory:
- IndirectDecompressor (Hadoop Decompressor wrapper)
- FullDirectDecompressor (Hadoop DirectDecompressionCodec via reflection)
- DirectCodecPool (pooled Hadoop compressor/decompressor instances)
- Static reflection fields for DirectDecompressionCodec discovery

Unsupported codecs and BROTLI without brotli4j now throw
UnsupportedOperationException instead of falling through to Hadoop.

Also removes the commons-pool:commons-pool dependency which was only
used by DirectCodecPool.
Delete the Hadoop CompressionCodec implementations that are no longer
used now that CodecFactory exclusively uses direct library calls:

Deleted codec classes:
- SnappyCodec, SnappyCompressor, SnappyDecompressor
- ZstandardCodec, ZstdCompressorStream, ZstdDecompressorStream
- Lz4RawCodec, Lz4RawCompressor, Lz4RawDecompressor
- NonBlockedCompressor, NonBlockedDecompressor
- NonBlockedCompressorStream, NonBlockedDecompressorStream

Deleted tests that exercised the Hadoop codec classes directly:
- TestCompressionCodec, TestSnappyCodec, TestZstandardCodec

Move ZSTD configuration constants (PARQUET_COMPRESS_ZSTD_LEVEL,
PARQUET_COMPRESS_ZSTD_WORKERS) from the deleted ZstandardCodec into
CodecFactory where they are now consumed.

Update TestDirectCodecFactory and TestDataPageChecksums to use
CodecFactory constants and direct Snappy JNI respectively.
Create a new parquet-compression module that contains all compression
codec implementations (Snappy, ZSTD, LZ4, GZIP, LZO, Brotli) without
any Hadoop dependencies. This allows non-Hadoop users to get compression
support without pulling in the Hadoop classpath.

New module: parquet-compression
- DefaultCompressionCodecFactory: full compression/decompression logic
- Dependencies: parquet-common, snappy-java, zstd-jni, aircompressor,
  brotli4j (optional/runtime)
- Zero Hadoop dependencies

parquet-hadoop changes:
- CodecFactory now extends DefaultCompressionCodecFactory, providing
  only Hadoop Configuration-based constructors for backward compat
- DirectCodecFactory unchanged (still extends CodecFactory)
- Compression library dependencies moved to parquet-compression
- Added parquet-compression as a dependency
Add TestDefaultCompressionCodecFactory with 12 tests covering:
- Round-trip compress/decompress for all 6 codecs (SNAPPY, GZIP, ZSTD,
  LZ4_RAW, LZO, BROTLI)
- Multiple data sizes (0 bytes to 256KB)
- ZSTD compression level configuration
- ZSTD multi-threaded workers configuration
- GZIP compression level configuration
- Compressor reuse safety (consecutive compressions)
- UNCOMPRESSED pass-through

These tests run without Hadoop, validating the compression module
operates independently.
…asses

Split the monolithic 832-line DefaultCompressionCodecFactory into focused
single-responsibility classes with minimum visibility:

- DefaultCompressionCodecFactory (public): factory logic, caching,
  constants, BytesCompressor/BytesDecompressor abstract classes
- SnappyCodec (package-private): Snappy JNI compress/decompress
- ZstdCodec (package-private): zstd-jni context-based compress/decompress
- Lz4RawCodec (package-private): airlift LZ4 with direct buffers
- GzipCodec (package-private): JDK GZIPOutputStream/GZIPInputStream
- LzoCodec (package-private): airlift LzoHadoopStreams
- BrotliCodec (package-private): delegates to Brotli4j helper
- Brotli4j (public): reflection-based brotli4j access, public because
  DirectCodecFactory in parquet-hadoop also needs it

Each codec class is final with a private constructor (utility pattern).
Inner Compressor/Decompressor classes are package-private static final.
…on helper

Promote brotli4j from runtime/optional to a compile dependency and
remove the Brotli4j reflection helper class entirely. BrotliCodec and
DirectCodecFactory now use brotli4j's Encoder/Decoder APIs directly.

Changes:
- parquet-compression pom: brotli4j is now a regular compile dependency
- Deleted Brotli4j.java (reflection-based helper)
- Rewrote BrotliCodec to use Encoder.compress/Decoder.decompress directly
- Rewrote DirectCodecFactory Brotli classes to use brotli4j directly
- Removed Brotli4j.AVAILABLE guards (brotli4j is always on classpath)
- Removed unused slf4j-api dependency from parquet-compression
- Removed redundant brotli4j dependency from parquet-hadoop pom
snappy-java, aircompressor, and zstd-jni are now provided transitively
via the parquet-compression dependency.
Move DirectCodecFactory from parquet-hadoop to parquet-compression,
eliminating the last direct compression library imports from parquet-hadoop.

DirectCodecFactory now takes ParquetConfiguration instead of Hadoop
Configuration. CodecFactory in parquet-hadoop becomes a minimal deprecated
shim that provides only Hadoop Configuration-based constructors.

parquet-hadoop's dependency on parquet-compression is now purely for the
deprecated CodecFactory shim's inheritance. All compression logic lives
entirely in parquet-compression with zero Hadoop dependencies.
@iemejia iemejia force-pushed the parquet-perf-v2-par6-compression branch from 0571b9e to 5de3272 Compare July 11, 2026 05:50
Apply palantir-java-format rules to DirectCodecFactory and
TestDefaultCompressionCodecFactory: join short lines that fit within
the column limit, and break method chains and long argument lists
according to the project style.

Assisted-by: GitHub Copilot:claude-opus-4.6
@iemejia iemejia force-pushed the parquet-perf-v2-par6-compression branch 2 times, most recently from c493dd6 to 402f4c5 Compare July 11, 2026 08:09
The japicmp plugin fails because:
1. commons-pool classes (BasePoolableObjectFactory, GenericObjectPool) are no longer
   transitively available after removing the Hadoop codec pool path
2. Public codec classes were moved from parquet-hadoop to parquet-compression
3. CodecFactory was refactored to extend DefaultCompressionCodecFactory
4. Deprecated constructors in ParquetRecordWriter and ColumnChunkPageWriteStore
   changed their BytesCompressor parameter type

Add ignoreMissingClassesByRegularExpression for org.apache.commons.pool and
exclude all moved/refactored classes from the compatibility check.
@iemejia iemejia force-pushed the parquet-perf-v2-par6-compression branch from 402f4c5 to 537ce63 Compare July 11, 2026 08:21
iemejia added 2 commits July 11, 2026 10:46
TestDataPageChecksums directly uses org.xerial.snappy.Snappy for
computing expected compressed checksums. After extracting compression
code to parquet-compression, snappy-java is only transitively available
but the dependency plugin requires it to be explicitly declared.
CodecFactory.createDirectCodecFactory() now returns
DefaultCompressionCodecFactory, not CodecFactory. Update the
benchmark to use the parent type directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant