[PATCH] optimization opportunity regarding misuse of BufferedInputStream
Сергей Цыпанов
sergei.tsypanov at yandex.ru
Fri Aug 28 13:29:47 UTC 2020
Hi,
> Isn't this InputStream::readAllBytes?
thanks for pointing this out! Indeed, InputStream::readAllBytes() allows to save even more memory:
Mode Cnt Score Error Units
read avgt 50 227.054 ± 1.354 us/op
read:·gc.alloc.rate.norm avgt 50 138605.638 ± 20.778 B/op
readNoVerify avgt 50 226.606 ± 1.748 us/op
readNoVerify:·gc.alloc.rate.norm avgt 50 137810.392 ± 7.020 B/op
Would you sponsor the changes?
Regards,
Sergey Tsypanov
28.08.2020, 12:08, "Florian Weimer" <fweimer at redhat.com>:
> * Сергей Цыпанов:
>
>> @@ -105,12 +105,8 @@
>> private byte[] getBytes(InputStream is)
>> throws IOException
>> {
>> - byte[] buffer = new byte[8192];
>> ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
>> - int n;
>> - while ((n = is.read(buffer, 0, buffer.length)) != -1) {
>> - baos.write(buffer, 0, n);
>> - }
>> + is.transferTo(baos);
>> return baos.toByteArray();
>> }
>
> Isn't this InputStream::readAllBytes?
>
> Thanks,
> Florian
More information about the core-libs-dev
mailing list