On Fri, 22 Jan 2021 16:21:05 GMT, Brian Burkhalter <b...@openjdk.org> wrote:
>> this is minor optimization following JDK-8254078. >> based on my tests with jmh, it has better performance when apply following >> patch: >> >> diff --git a/src/java.base/share/classes/java/io/DataOutputStream.java >> b/src/java.base/share/classes/java/io/DataOutputStream.java >> index 9a9a687403c..4ea497fc7c0 100644 >> --- a/src/java.base/share/classes/java/io/DataOutputStream.java >> +++ b/src/java.base/share/classes/java/io/DataOutputStream.java >> @@ -300,8 +300,9 @@ public class DataOutputStream extends FilterOutputStream >> implements DataOutput { >> int len = s.length(); >> for (int i = 0 ; i < len ; i++) { >> int v = s.charAt(i); >> - out.write((v >>> 8) & 0xFF); >> - out.write((v >>> 0) & 0xFF); >> + writeBuffer[0] = (byte)(v >>> 8); >> + writeBuffer[1] = (byte)(v >>> 0); >> + out.write(writeBuffer, 0, 2); >> } >> incCount(len * 2); >> } >> >> Basically, it has better performance when apply above patch: >> >> // without writeChars optimization patch, (-XX:-UseBiasedLocking) >> Benchmark (basicType) (size) Mode Cnt Score Error Units >> DataOutputStreamTest.dataOutputStreamOverBufferedFileStream STRING 4096 avgt >> 6 115.208 ± 0.327 us/op >> DataOutputStreamTest.dataOutputStreamOverByteArray STRING 4096 avgt 6 >> 276.795 ± 0.449 us/op >> DataOutputStreamTest.dataOutputStreamOverRawFileStream STRING 4096 avgt 6 >> 12356.969 ± 22.427 us/op >> >> // with writeChars optimization patch, (-XX:-UseBiasedLocking) >> Benchmark (basicType) (size) Mode Cnt Score Error Units >> DataOutputStreamTest.dataOutputStreamOverBufferedFileStream STRING 4096 avgt >> 6 133.706 ± 0.274 us/op >> DataOutputStreamTest.dataOutputStreamOverByteArray STRING 4096 avgt 6 >> 130.979 ± 0.155 us/op >> DataOutputStreamTest.dataOutputStreamOverRawFileStream STRING 4096 avgt 6 >> 6814.272 ± 52.770 us/op >> >> >> // without writeChars optimization patch, (-XX:+UseBiasedLocking) >> Benchmark (basicType) (size) Mode Cnt Score Error Units >> DataOutputStreamTest.dataOutputStreamOverBufferedFileStream STRING 4096 avgt >> 6 130.367 ± 8.759 us/op >> DataOutputStreamTest.dataOutputStreamOverByteArray STRING 4096 avgt 6 37.559 >> ± 0.059 us/op >> DataOutputStreamTest.dataOutputStreamOverRawFileStream STRING 4096 avgt 6 >> 12385.030 ± 376.560 us/op >> >> // with writeChars optimization patch, (-XX:+UseBiasedLocking) >> Benchmark (basicType) (size) Mode Cnt Score Error Units >> DataOutputStreamTest.dataOutputStreamOverBufferedFileStream STRING 4096 avgt >> 6 45.494 ± 7.018 us/op >> DataOutputStreamTest.dataOutputStreamOverByteArray STRING 4096 avgt 6 33.015 >> ± 0.349 us/op >> DataOutputStreamTest.dataOutputStreamOverRawFileStream STRING 4096 avgt 6 >> 6845.549 ± 38.712 us/op > > Marked as reviewed by bpb (Reviewer). Hi Roger, Brian, Thanks for reviewing, and long time no see :-). ------------- PR: https://git.openjdk.java.net/jdk/pull/2190