Skip to content

[C++][Parquet] Expose the API to fine tune the window_bits parameter of ZLIB compression  #35287

Closed

Description

@yyang52

Describe the enhancement requested

ZLIB library supports history buffers of different sizes by setting windowBits parameter, while currently in Arrow it is set as a fixed value. It makes sense that setting the window size to the maximum number will give a better performance, while it does not provide too much flexibility. As we know there would be some scenarios where the memory efficiency is very limited, or the software stack is relatively old and do not have a large memory capacity. For those cases, the user may want to set the window bits to a small number to save some memory. At least it would be much more flexible to give users such an option to choose the window size when de/compressing. If that makes sense, we would like to add such a property for the user to set the ZLIB(GZIP) window_bits, and will ensure not affecting the existing function calls. Thanks!

Component(s)

C++, Parquet

Activity

  1. mapleFU commented on Apr 23, 2023

    @mapleFU
    Member

    Maybe you can just the style of compression_level to pass the argument in?

  2. yyang52 commented on Apr 23, 2023

    @yyang52
    ContributorAuthor

    Maybe you can just the style of compression_level to pass the argument in?

    Hi, thanks for your quick reply! Do you mean we could add another parquet writer property (maybe can call it window_bits) just like how compression_level passed in? That's also what we are trying to do now :)

  3. mapleFU commented on Apr 23, 2023

    @mapleFU
    Member

    By the way, currently, arrow compression arguments are just level. Maybe we can support argument like rocksdb: https://github.com/facebook/rocksdb/blob/main/include/rocksdb/advanced_options.h#L87

  4. yyang52 commented on Apr 23, 2023

    @yyang52
    ContributorAuthor

    By the way, currently, arrow compression arguments are just level. Maybe we can support argument like rocksdb: https://github.com/facebook/rocksdb/blob/main/include/rocksdb/advanced_options.h#L87

    Yes, it will give much more flexibility! Seems like rocksdb already support window_bits as an option, and many other arguments as well. Maybe I could help to draft a PR to add the window_bits option (or any other if needed) to Arrow as a kickoff?

  5. mapleFU commented on Apr 23, 2023

    @mapleFU
    Member

    Personally I'm +1 for this, but please not break original interface a lot, maybe just change it firstly:

    std::unique_ptr<Codec> MakeGZipCodec(int compression_level, GZipFormat::type format) {
      return std::make_unique<GZipCodec>(compression_level, format);
    }

    And use MakeGZipCodec in src/arrow/util/compression_internal.h firstly. Later we can extend it. Do you think this is ok?

  6. yyang52 commented on Apr 23, 2023

    @yyang52
    ContributorAuthor

    Personally I'm +1 for this, but please not break original interface a lot, maybe just change it firstly:

    std::unique_ptr<Codec> MakeGZipCodec(int compression_level, GZipFormat::type format) {
      return std::make_unique<GZipCodec>(compression_level, format);
    }

    And use MakeGZipCodec in src/arrow/util/compression_internal.h firstly. Later we can extend it. Do you think this is ok?

    Yes we would definitely not break the original interface. Change MakeGZipCodec is also what I want to do first! The only thing I need to double confirm is that since we want to pass the argument from user level to the function MakeGZipCodec, we may need to add another property similar to compression_level in parquet writer and pass it down to the compression_internal right? Then user can set the window_bits when creating the parquet writer :)

  7. mapleFU commented on Apr 23, 2023

    @mapleFU
    Member

    I'm ok on this.
    @wjones127 @kou What's your opinion for adding a window_bits here?

  8. changed the title [-]Expose the API to fine tune the window_bits parameter of ZLIB compression [/-] [+][C++][Parquet] Expose the API to fine tune the window_bits parameter of ZLIB compression [/+] on Apr 23, 2023
  9. kou commented on Apr 23, 2023

    @kou
    Member

    I'm OK with make window_bits customizable.
    But I don't think that calling MakeGZipCodec() from cpp/parquet/ directly is a good idea.
    Currently, we use Codec::Create() instead of Make*Codec() directly in cpp/parquet/.

    I don't think that adding a new parameter Codec::Create() such as Codec::Create(Compression::type codec, int compression_level, int window_bits) is a good idea.
    If we choose this approach, we may need to add more parameters later.
    I like that we introduce a new options class such as Codec::Options but it may be too complex.

    I suggest that we discuss API on [email protected] too.

  10. george-gu-2021 commented on Apr 23, 2023

    @george-gu-2021

    Given the variety of usage scenarios, it does be quite helpful to expose the capability and flexibility to applications to decide the codec parameter.

  11. yyang52 commented on Apr 23, 2023

    @yyang52
    ContributorAuthor

    I'm OK with make window_bits customizable. But I don't think that calling MakeGZipCodec() from cpp/parquet/ directly is a good idea. Currently, we use Codec::Create() instead of Make*Codec() directly in cpp/parquet/.

    I don't think that adding a new parameter Codec::Create() such as Codec::Create(Compression::type codec, int compression_level, int window_bits) is a good idea. If we choose this approach, we may need to add more parameters later. I like that we introduce a new options class such as Codec::Options but it may be too complex.

    I suggest that we discuss API on [email protected] too.

    Thanks for your suggestion @kou! I agree that introducing a new option class is a better design and will make the extension of the parameters much easier. And it's also true that it will be more complex to do such a refactor. Do I need to initialize a discussion on [email protected] cause I have not used that before, thanks!

  12. mapleFU commented on Apr 23, 2023

    @mapleFU
    Member
  13. 5 remaining items

  14. yyang52 commented on Apr 25, 2023

    @yyang52
    ContributorAuthor

    When building parquet::WriterProperties, there could be 2 design options: one is to pass compression parameters separately (as the current implementation, with more properties to be added) and make CodecOptions internally, for example:

     std::shared_ptr<parquet::WriterProperties> props =
              builder.compression(parquet::Compression::GZIP)
                  ->compression_level(9)
                  ->set_gzip_format(parquet::GZipFormat::DEFLATE)
                  ->gzip_window_bits(12)
                  ->build();

    Another is to let the user create a CodecOption and pass the option to the builder directly:

    CodecOption opt;
    opt.compression_level = 9;
    opt.window_bits = 12; 
    std::shared_ptr<parquet::WriterProperties> props =
              builder.compression(parquet::Compression::GZIP)
                  ->codec_option(opt)
                  ->build();
    

    Which one do you prefer? Thanks! @kou @wgtmac @mapleFU

  15. mapleFU commented on Apr 25, 2023

    @mapleFU
    Member

    (2) is much better for me.

  16. wgtmac commented on Apr 25, 2023

    @wgtmac
    Member

    I'd vote for (2) and adopt CodecOption proposed by @pitrou in the mailing list.

  17. mapleFU commented on Apr 25, 2023

    @mapleFU
    Member

    @wgtmac If we want it in mailiist, maybe we need a std::unique_ptr<CodecOption>?

  18. wgtmac commented on Apr 25, 2023

    @wgtmac
    Member

    @wgtmac If we want it in mailiist, maybe we need a std::unique_ptr<CodecOption>?

    It would be a std::shared_ptr<CodecOption> or we cannot copy WriterProperties any more.

  19. kou commented on Apr 25, 2023

    @kou
    Member

    I prefer the latter too.
    But I want to use CodecOptions not CodecOption because other existing options class has s.
    For example, EqualOptions, ArithmeticOptions and so on.

    I seems that we can use std::shared_ptr<CodecOptions> for this. Or we may want to copy CodecOptions instead of sharing it by std::shared_ptr.

  20. yyang52 commented on Apr 26, 2023

    @yyang52
    ContributorAuthor

    Thanks for all your suggestions! So I'd go with the latter one with std::shared_ptr<CodecOptions>

  21. added a commit that references this issue on Jul 11, 2023
  22. added this to the 13.0.0 milestone on Jul 11, 2023
  23. modified the milestones: 13.0.0, 14.0.0 on Jul 13, 2023
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