Skip to content

[C++] GZipCodec::Init does deflateInit and immediately throws it away #51308

Closed

Description

@lorenzhs

Describe the bug, including details regarding any error messages, version, and platform.

Performance issue in GZipCodec, no crashes/wrong results/..., but I still think it's a bug.

const Status init_compressor_status = InitCompressor();
if (!init_compressor_status.ok()) {
return init_compressor_status;
}
return InitDecompressor();

This is wasteful: InitCompressor on line 497 calls deflateInit2, which at windowBits=15 and memLevel=8 allocates roughly 256 KB. InitDecompressor on line 501 calls EndCompressor which does deflateEnd and frees it again. It's pure waste. The only thing it gives us is some validation on the compression level.

The current code leaves the GZipCodec with a valid decompressor (which also allocates, but less) which is fine for the case where the caller wants to use the codec to do decompression, but is extra-wasteful for the case where the caller wants to compress: it allocates a compressor, frees it, allocates a decompressor, frees it, then allocates a compressor again.

I think the correct fix is firebolt-db#47, I'm happy to file it as a PR here as well.

Component(s)

C++

Activity

  1. changed the title [-]GZipCodec::Init does deflateInit and immediately throws it away[/-] [+][C++] GZipCodec::Init does deflateInit and immediately throws it away[/+] on Sep 11, 2026
  2. La1itchauhan commented on Sep 22, 2026

    @La1itchauhan

    Hi @lorenzhs, are you currently planning to open a PR for this upstream, or would you mind if I helped port the lazy initialization fix from firebolt-db#47 to apache/arrow (with you credited as co-author)? Happy to take care of the upstream PR, CI, and test coverage!

  3. lorenzhs commented on Sep 24, 2026

    @lorenzhs
    ContributorAuthor

    Lol, no need. I was hoping for a maintainer reaction before opening a PR, I do not need someone to click the button for me.

  4. added a commit that references this issue on Oct 6, 2026
  5. added this to the 27.0.0 milestone on Oct 6, 2026
  6. pitrou commented on Oct 6, 2026

    @pitrou
    Member

    Issue resolved by pull request 51483
    #51483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions