Integrated: 8341597: ZipFileInflaterInputStream input buffer size uses uncompressed size
Eirik Bjørsnøs
eirbjo at openjdk.org
Tue Oct 8 10:02:03 UTC 2024
On Sun, 6 Oct 2024 18:02:58 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:
> Please review this PR which proposes to change the input buffer size of `ZipFileInflaterInputStream` to be based on the _compressed_ size of a ZIP entry instead of the _uncompressed_ size. This saves allocation since buffers will no longer be oversized:
>
> * The `size` parameter passed to the `ZipFileInflaterInputStream` constructor is passed on to the superclass `InflaterInputStream` where it determines the size of the input buffer. This buffer is used to read compressed data and pass it on to the `Inflater`.
> * `ZipFile:getInputStream` currently looks at the _uncompressed_ size when determining the input buffer size. It should instead use the _compressed_ size, since this buffer is used for compressed, not uncompressed data.
> * The current implementation somewhat mysteriously adds 2 to the uncompressed size. My guess is that this is to allow fitting a two-byte DEFLATE header for empty files (where the uncompressed size is 0 and the compressed size is 2).
> * There is a check for `size <= 0`. This condition is unreachable in the current code and in the PR as well, since the compressed size will always be `>= 2`. I propose we remove this check.
>
> Performance: A benchmark which measures the cost of opening and closing input streams using `ZipFile::getInputStream` shows a modest improvement of ~5%, consistent with less allocation of unused buffer space.
>
> Testing: No tests are added in this PR. The `noreg-cleanup` label is added in JBS. GHA testing is currently pending.
This pull request has now been integrated.
Changeset: f62dba36
Author: Eirik Bjørsnøs <eirbjo at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/f62dba3651719bc0031522e171a6e42b362c1363
Stats: 4 lines in 1 file changed: 0 ins; 3 del; 1 mod
8341597: ZipFileInflaterInputStream input buffer size uses uncompressed size
Reviewed-by: lancea
-------------
PR: https://git.openjdk.org/jdk/pull/21379
More information about the core-libs-dev
mailing list