jruby / jcodings

Java-based codings helper classes for Joni and JRuby
MIT License
21 stars 29 forks source link

Reduce the number of individual InputStream#read calls by reading in batches. #21

Closed nirvdrum closed 6 years ago

nirvdrum commented 6 years ago

Individual reads from ZipFileInputStream, as would be encountered when reading a resource from a JAR, can be very inefficient. They allocate a single-byte array and require unzipping the source file for each read (at least in OpenJDK 8).

headius commented 6 years ago

As mentioned on IRC, I would like to see if a simple BufferedInputStream has the same impact, since it would be simpler code and would not need to read the zipped content entirely into memory.

nirvdrum commented 6 years ago

BufferedInputStream might be a tad slower because it will end up opening the JAR file multiple times, but I think it borders on inconsequential. I've updated the PR to use it since it's much clearer.