RFR: 8320971: Use BufferedInputStream.buf directly when param of implTransferTo() is trusted [v17]
Markus KARG
duke at openjdk.org
Fri Dec 22 15:11:54 UTC 2023
On Fri, 22 Dec 2023 14:37:26 GMT, Vladimir Sitnikov <vsitnikov at openjdk.org> wrote:
>> I think there is a misundertanding. This PR is not intendend to reduce the *amount* of allocated heap, it is about sparing time by not creating *temporary copies*. The latter should be rather easy to check: Invoke `transferTo(out)` two times in a row and compare the *identity* of the two byte arrays passed to `out.write()`. If they stay the same, then apparently no *temporary copy* was created. Two achieve this, the BIS must be wrapper around an extendable input stream (like `FileInputStream`) so between calls the stream could get extended (e. g. by writing into the file).
>
> Markus, could you please double-check? A temporary allocation *is* an allocation, and it is the point of the change to avoid allocation and copying the temp data when the output stream is known to behave well. I am sure the allocation "before the change" would be non-trivial (more than several KiB), and after the change the allocation within .transferTo would be minimal (few bytes) assuming the output stream has already allocated its buffer
IMHO the trigger for this PR was sparing *time*, not necessarily sparing *bytes* (the default buffer size is just 8K); the latter certainly is a nice and beneficial side effect. But I may be wrong here, then the original contributor should chime in now and clarify.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16879#discussion_r1435146173
More information about the core-libs-dev
mailing list