Why does ZipFile.Source.readFullyAt read in chunks?

Eirik Bjørsnøs eirbjo at gmail.com
Fri Jan 27 23:23:25 UTC 2023


Hi,

ZipFile.Source.readFullyAt caps its calls to RandomAccessFile.readFully to
a maximum of 8192 bytes per call, like this:

int N = len;
> while (N > 0) {
>     int n = Math.min(BUF_SIZE, N);
>     zfile.readFully(buf, off, n);
>     off += n;
>     N -= n;
> }


I'm observing a ~10% speedup of the ZipFileOpen micro when I replace the
above with simply:

zfile.seek(pos);
> zfile.readFully(buf, off, len);


Does anyone know why readFullyAt is implemented this way? Is it trying to
limit blocking time somehow? Is there some hidden buffering deeper down I'm
not seeing?

If this is safe to remove, I'm happy to submit a PR. But code like this is
usually there for a reason..?

Cheers,
Eiirk.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20230128/58649bc9/attachment.htm>


More information about the core-libs-dev mailing list