Skip to content

Clarification on default JdkZlibEncoder compression level #15212

Closed

Description

@daschl

In JdkZlibEncoder, the javadoc specifies:

     * @param compressionLevel
     *        {@code 1} yields the fastest compression and {@code 9} yields the
     *        best compression.  {@code 0} means no compression.  The default
     *        compression level is {@code 6}.

Now this is true in case the overload with no compression level is used:

    /**
     * Creates a new zlib encoder with the default compression level ({@code 6})
     * and the specified wrapper.
     *
     * @throws CompressionException if failed to initialize zlib
     */
    public JdkZlibEncoder(ZlibWrapper wrapper) {
        this(wrapper, 6);
    }

But if you look into the java.util.zip.Deflater that gets created in the constructor, it actually specifies:

    /**
     * Default compression level.
     */
    public static final int DEFAULT_COMPRESSION = -1;

Is there any reason why the netty default compression level deviates from the underlying Deflater default compression level?

Activity

  1. daschl commented on May 20, 2025

    @daschl
    MemberAuthor

    One more comment on this. If we want to allow the default compression level of the Deflater to set, we also need to change the constructor of the JdkZlibEncoder since right now it checks a range from 0 to 9.

  2. normanmaurer commented on May 20, 2025

    @normanmaurer
    Member

    @daschl honestly I can't remember why we used this value. Maybe @trustin remembers ?

  3. trustin commented on May 20, 2025

    @trustin
    Member

    I don't remember the exact detail since it was written long time ago, but according to zlib manual:

    The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION requests a default compromise between speed and compression (currently equivalent to level 6).

  4. trustin commented on May 20, 2025

    @trustin
    Member

    I think we can make a change so it accepts -1 as the default.

  5. daschl commented on May 20, 2025

    @daschl
    MemberAuthor

    Another more conservative approach we could as a first step is to allow at least -1 as a value being passed in? than it is backwards compatible and users who want to set -1 can do so.

  6. normanmaurer commented on May 20, 2025

    @normanmaurer
    Member

    @daschl sounds like a plan... Please send over a PR

  7. added a commit that references this issue on May 20, 2025
    e0e463d
  8. self-assigned this
    on May 20, 2025
  9. added a commit that references this issue on May 20, 2025
    4e590c2
  10. added this to the 4.2.2.Final milestone on May 20, 2025
  11. added 2 commits that reference this issue on May 20, 2025
    0f9c126
    0b7b5e2
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