RFR: 8325340: Add ASCII fast-path to Data-/ObjectInputStream.readUTF

Claes Redestad redestad at openjdk.org
Tue Feb 13 16:13:12 UTC 2024


On Tue, 6 Feb 2024 16:17:21 GMT, Claes Redestad <redestad at openjdk.org> wrote:

> Adding a fast-path for ASCII-only modified UTF-8 strings deserialied via Data- and ObjectInputStream
> 
> Testing: tier1-3

Benchmark numbers

M1 MacBook:

Name                                        Cnt  Base   Error   Test   Error  Unit  Change
DataInputStreamTest.readUTFAsciiLarge        20 1,517 ± 0,018  1,052 ± 0,014 us/op   1,44x (p = 0,000*)
DataInputStreamTest.readUTFAsciiMixed        20 1,391 ± 0,012  1,034 ± 0,021 us/op   1,34x (p = 0,000*)
DataInputStreamTest.readUTFAsciiSmall        20 1,017 ± 0,019  1,007 ± 0,010 us/op   1,01x (p = 0,085 )
DataInputStreamTest.readUTFLarge             20 2,109 ± 0,032  2,025 ± 0,028 us/op   1,04x (p = 0,000*)
DataInputStreamTest.readUTFMixed             20 1,651 ± 0,085  1,615 ± 0,025 us/op   1,02x (p = 0,124 )
DataInputStreamTest.readUTFSmall             20 1,020 ± 0,015  1,021 ± 0,014 us/op   1,00x (p = 0,773 )
ObjectInputStreamTest.readUTFAsciiLarge      15 3,094 ± 0,064  1,070 ± 0,018 us/op   2,89x (p = 0,000*)
ObjectInputStreamTest.readUTFAsciiMixed      15 2,670 ± 0,062  0,779 ± 0,024 us/op   3,43x (p = 0,000*)
ObjectInputStreamTest.readUTFAsciiSmall      15 1,138 ± 0,037  0,594 ± 0,026 us/op   1,92x (p = 0,000*)
ObjectInputStreamTest.readUTFLarge           15 4,714 ± 0,049  3,040 ± 0,023 us/op   1,55x (p = 0,000*)
ObjectInputStreamTest.readUTFMixed           15 2,952 ± 0,032  2,358 ± 0,024 us/op   1,25x (p = 0,000*)
ObjectInputStreamTest.readUTFSmall           15 1,544 ± 0,169  1,259 ± 0,055 us/op   1,23x (p = 0,000*)
  * = significant
 ```
 
 Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz, Linux:
 ```
Name                                        Cnt   Base   Error    Test   Error  Unit  Change
DataInputStreamTest.readUTFAsciiLarge        20  2.827 ± 0.006   2.098 ± 0.016 us/op   1.35x (p = 0.000*)
DataInputStreamTest.readUTFAsciiMixed        20  2.453 ± 0.009   2.071 ± 0.010 us/op   1.18x (p = 0.000*)
DataInputStreamTest.readUTFAsciiSmall        20  1.957 ± 0.005   2.052 ± 0.015 us/op   0.95x (p = 0.000*)
DataInputStreamTest.readUTFLarge             20  4.339 ± 0.038   4.057 ± 0.017 us/op   1.07x (p = 0.000*)
DataInputStreamTest.readUTFMixed             20  3.494 ± 0.007   3.387 ± 0.042 us/op   1.03x (p = 0.000*)
DataInputStreamTest.readUTFSmall             20  2.257 ± 0.009   2.309 ± 0.016 us/op   0.98x (p = 0.000*)
ObjectInputStreamTest.readUTFAsciiLarge      15  5.056 ± 0.028   1.827 ± 0.021 us/op   2.77x (p = 0.000*)
ObjectInputStreamTest.readUTFAsciiMixed      15  3.492 ± 0.107   1.221 ± 0.011 us/op   2.86x (p = 0.000*)
ObjectInputStreamTest.readUTFAsciiSmall      15  1.651 ± 0.014   0.976 ± 0.018 us/op   1.69x (p = 0.000*)
ObjectInputStreamTest.readUTFLarge           15  9.741 ± 0.034   6.049 ± 0.039 us/op   1.61x (p = 0.000*)
ObjectInputStreamTest.readUTFMixed           15  5.786 ± 0.082   4.220 ± 0.008 us/op   1.37x (p = 0.000*)
ObjectInputStreamTest.readUTFSmall           15  2.219 ± 0.075   1.405 ± 0.013 us/op   1.58x (p = 0.000*)
  * = significant


For the `Small` variants of the `DataInputStream` the optimization doesn't pay off inputs less than 8 bytes. The added cost seen here is due the increased code complexity and an added branch, without the `utflen > 7` checks the `readUTFSmall` (slow-path test) would score 0.6-0.7x which was unacceptable.

For the `ObjectInputStream` case the fast-path additionally helps avoid the need for a `StringBuilder` if the byte length of the UTF record fits in the shared `char[]`.

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

PR Comment: https://git.openjdk.org/jdk/pull/17734#issuecomment-1930221329


More information about the core-libs-dev mailing list