On Sat, 23 Dec 2023 13:01:09 GMT, Markus KARG <d...@openjdk.org> wrote:
>Typically it was sufficient to document the JMH results before and after a PR >just once (not dynamically in the form of a test). The problem with "results before and after a PR just once" is those benchmarks will not automatically fail the build if somebody else breaks the optimization unintentionally. In other words, benchmarks do not serve as a safety net. At the same time, if the test code were to ensure "less than 20 bytes allocated" in a common case of transferring data from `BufferedInputStream` to `ByteArrayOutputStream`, then it would be a nice safety net so the optimization will not be broken unintentionally. >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, I am afraid you missed that anything that "extends FileOutputStream" (I assume you mean `FileOutputStream`, not `FileInputStream`) would **not** qualify as a trusted stream, and `transferTo` will make a copy. The current check is `clazz == FileOutputStream.class` ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/16879#discussion_r1435625914