perf(compression): initialize gzip codec state lazily - #47
Merged
Merged
Conversation
Creating a GZipCodec eagerly initialized compressor state and then immediately discarded it while initializing decompressor state. Callers using the streaming factories therefore paid for unrelated codec state during construction. Keep construction-time option validation, but leave compressor and decompressor allocation to the existing lazy initialization paths. Extend the option tests to cover compression-level and window-size validation independently.
lorenzhs
marked this pull request as ready for review
September 11, 2026 13:32
tobias-fire
approved these changes
Sep 11, 2026
tobias-fire
left a comment
There was a problem hiding this comment.
Stamping, but feels a bit strange to remove the InitCompressor() call from the Init() function completely. I would prefer a solution where we keep it, e.g. by only creating the decompression codec once per range reader, instead of once per page. Maybe that would be a good idea anyways?
lorenzhs
marked this pull request as draft
September 11, 2026 14:07
lorenzhs
marked this pull request as ready for review
September 11, 2026 14:08
lorenzhs
force-pushed
the
lorenz/gzip-lazy-init
branch
from
September 11, 2026 15:00
e29a56f to
47f7f73
Compare
Collaborator
Author
|
It's totally safe, the flow is essentially auto status = InitCompressor();
assert(status.ok());
InitDecompressor();and |
lorenzhs
marked this pull request as draft
September 11, 2026 15:04
lorenzhs
marked this pull request as ready for review
September 11, 2026 15:26
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.
Rationale for this change
GZipCodec::Init()initializes compressor state and then immediately initializes decompressor state, which tears the compressor state down again. Decompression-only callers therefore pay for an unrelated zlib workspace allocation and initialization.What changes are included in this PR?
GZipCodec::Init()now validates the compression level and window size without allocating codec state. The existing lazy paths inCompress(),Decompress(),MaxCompressedLen(),MakeCompressor(), andMakeDecompressor()initialize the state they actually use.The gzip option tests cover compression level and window-size validation independently, including compression level zero.
Are these changes tested?
The Arrow library builds successfully with the enabled compression backends. Existing codec tests exercise one-shot compression, one-shot decompression, and streaming construction in CI, with focused option coverage for the validation retained by
Init().Are there any user-facing changes?
No API or format behavior changes. Gzip codec state is initialized on first use instead of during codec construction.