RFR: 8339699: Optimize DataOutputStream writeUTF

Shaojin Wen swen at openjdk.org
Sat Sep 7 07:55:38 UTC 2024


On Fri, 6 Sep 2024 09:58:58 GMT, Shaojin Wen <swen at openjdk.org> wrote:

> PR #20772 introduced an optimization for writeUTF, which can also be used in DataOutputStream::writeUTF.

Below are the performance numbers running on a MacBook M1 Pro. Both DataOutputStreamBench::writeUTF and ObjectOutputStream::writeUTF have been significantly improved in various character sets.

## 1.1 Script


git remote add wenshao git at github.com:wenshao/jdk.git
git fetch wenshao

# baseline
git chekcout 42f47a8979f20457114e7c63d28d66db044b23dd
make test TEST="micro:java.io.DataOutputStreamBench"

# current
git checkout 30786c277bc006db6a55be267673878d7ea8db9b
make test TEST="micro:java.io.DataOutputStreamBench"


## 1.2 Performance Numbers

-# baseline
-Benchmark                                (charType)  Mode  Cnt   Score    Error  Units
-DataOutputStreamBench.dataOutwriteUTF         ascii  avgt   12  13.202 ?  0.238  us/op
-DataOutputStreamBench.dataOutwriteUTF  utf8_2_bytes  avgt   12  16.771 ?  0.145  us/op
-DataOutputStreamBench.dataOutwriteUTF  utf8_3_bytes  avgt   12  48.448 ?  0.112  us/op
-DataOutputStreamBench.dataOutwriteUTF         emoji  avgt   12  53.540 ? 30.963  us/op
-DataOutputStreamBench.objectWriteUTF          ascii  avgt   12   8.800 ?  0.017  us/op
-DataOutputStreamBench.objectWriteUTF   utf8_2_bytes  avgt   12  35.113 ?  0.058  us/op
-DataOutputStreamBench.objectWriteUTF   utf8_3_bytes  avgt   12  36.352 ?  0.152  us/op
-DataOutputStreamBench.objectWriteUTF          emoji  avgt   12  56.454 ?  0.069  us/op

+# current
+Benchmark                                (charType)  Mode  Cnt   Score   Error  Units
+DataOutputStreamBench.dataOutwriteUTF         ascii  avgt   12   5.292 ? 0.040  us/op
+DataOutputStreamBench.dataOutwriteUTF  utf8_2_bytes  avgt   12  11.678 ? 0.105  us/op
+DataOutputStreamBench.dataOutwriteUTF  utf8_3_bytes  avgt   12  27.907 ? 0.048  us/op
+DataOutputStreamBench.dataOutwriteUTF         emoji  avgt   12  49.144 ? 0.176  us/op
+DataOutputStreamBench.objectWriteUTF          ascii  avgt   12   4.693 ? 0.032  us/op
+DataOutputStreamBench.objectWriteUTF   utf8_2_bytes  avgt   12  16.993 ? 0.028  us/op
+DataOutputStreamBench.objectWriteUTF   utf8_3_bytes  avgt   12  23.619 ? 0.115  us/op
+DataOutputStreamBench.objectWriteUTF          emoji  avgt   12  41.335 ? 0.372  us/op


|   | charType | baseline  | current | delta |
| --- | --- | --- | --- | --- |
| DataOutputStreamBench.dataOutwriteUTF | ascii | 13.202 | 5.292 | 149.47% |
| DataOutputStreamBench.dataOutwriteUTF | utf8_2_bytes | 16.771 | 11.678 | 43.61% |
| DataOutputStreamBench.dataOutwriteUTF | utf8_3_bytes | 48.448 | 27.907 | 73.61% |
| DataOutputStreamBench.dataOutwriteUTF | emoji | 53.540 | 49.144 | 8.95% |
| DataOutputStreamBench.objectWriteUTF | ascii | 8.800 | 4.693 | 87.51% |
| DataOutputStreamBench.objectWriteUTF | utf8_2_bytes | 35.113 | 16.993 | 106.63% |
| DataOutputStreamBench.objectWriteUTF | utf8_3_bytes | 36.352 | 23.619 | 53.91% |
| DataOutputStreamBench.objectWriteUTF | emoji | 56.454 | 41.335 | 36.58% |

-------------

PR Comment: https://git.openjdk.org/jdk/pull/20886#issuecomment-2335108105


More information about the core-libs-dev mailing list