RFR: 8335182: Consolidate and streamline String concat code shapes
Claes Redestad
redestad at openjdk.org
Thu Jun 27 12:31:20 UTC 2024
This PR attains a speed-up on some microbenchmarks by simplifying how we build up the MH combinator tree shape
(only use prependers with prefix, always add a suffix to the newArray combinator), then simplifying/inlining some of the code in the helper functions.
Many simple concatenation expressions stay performance neutral, while the win comes from enabling C2 to better optimize more complex shapes (concat13String, concatMix4String, concatConst6String see relatively large improvements):
Name Cnt Base Error Test Error Unit Change
StringConcat.concat13String 50 66.380 ± 0.189 53.017 ± 0.241 ns/op 1.25x (p = 0.000*)
StringConcat.concat4String 50 13.620 ± 0.053 12.382 ± 0.089 ns/op 1.10x (p = 0.000*)
StringConcat.concat6String 50 17.168 ± 0.070 16.046 ± 0.064 ns/op 1.07x (p = 0.000*)
StringConcat.concatConst2String 50 9.820 ± 0.081 8.158 ± 0.041 ns/op 1.20x (p = 0.000*)
StringConcat.concatConst4String 50 14.938 ± 0.124 12.800 ± 0.049 ns/op 1.17x (p = 0.000*)
StringConcat.concatConst6Object 50 56.115 ± 0.288 54.046 ± 0.214 ns/op 1.04x (p = 0.000*)
StringConcat.concatConst6String 50 19.032 ± 0.073 16.213 ± 0.093 ns/op 1.17x (p = 0.000*)
StringConcat.concatConstBoolByte 50 8.486 ± 0.066 8.556 ± 0.050 ns/op 0.99x (p = 0.004*)
StringConcat.concatConstInt 50 8.942 ± 0.052 7.677 ± 0.029 ns/op 1.16x (p = 0.000*)
StringConcat.concatConstIntConstInt 50 12.883 ± 0.070 12.431 ± 0.070 ns/op 1.04x (p = 0.000*)
StringConcat.concatConstString 50 7.523 ± 0.050 7.486 ± 0.044 ns/op 1.00x (p = 0.058 )
StringConcat.concatConstStringConstInt 50 11.961 ± 0.032 11.699 ± 0.049 ns/op 1.02x (p = 0.000*)
StringConcat.concatEmptyConstInt 50 7.778 ± 0.038 7.723 ± 0.037 ns/op 1.01x (p = 0.000*)
StringConcat.concatEmptyConstString 50 3.506 ± 0.026 3.505 ± 0.015 ns/op 1.00x (p = 0.930 )
StringConcat.concatEmptyLeft 50 3.573 ± 0.075 3.518 ± 0.057 ns/op 1.02x (p = 0.044 )
StringConcat.concatEmptyRight 50 3.713 ± 0.049 3.622 ± 0.053 ns/op 1.02x (p = 0.000*)
StringConcat.concatMethodConstString 50 7.418 ± 0.030 7.478 ± 0.066 ns/op 0.99x (p = 0.005*)
StringConcat.concatMix4String 50 89.243 ± 0.436 71.866 ± 0.894 ns/op 1.24x (p = 0.000*)
StringConcatStartup.MixedLarge.run 10 655.436 ± 29.787 649.730 ± 26.053 ms/op 1.01x (p = 0.500 )
StringConcatStartup.MixedSmall.run 20 51.676 ± 2.324 50.724 ± 5.050 ms/op 1.02x (p = 0.512 )
StringConcatStartup.StringLarge.run 10 166.022 ± 15.672 165.300 ± 14.433 ms/op 1.00x (p = 0.873 )
StringConcatStartup.StringSingle.run 40 0.168 ± 0.016 0.178 ± 0.024 ms/op 0.94x (p = 0.234 )
* = significant
Startup-wise it's more or less neutral as evidenced by the added `StringConcatStartup` micro (a simplified and JMH:ified version of some startup stress tests I've been tinkering with over the years). This PR does not change the total number of classes generated and loaded by this test (3359 total, 2499 generated).
-------------
Commit messages:
- Add StringConcatStartup JMH
- Merge branch 'master' into consolidated_prependers
- Simplify
- Remove getBytes changes
- Streamline newArray
- Consolidate to always end with newArrayWithSuffix
- Merge branch 'master' into consolidated_prependers
- Streamline prependers
- Fix compilation errors from removing non-prefixed prepend methods
- Remove non-prefix prepender methods, inline logic into prefixed variant
- ... and 1 more: https://git.openjdk.org/jdk/compare/efb905e5...6525e945
Changes: https://git.openjdk.org/jdk/pull/19927/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19927&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8335182
Stats: 565 lines in 6 files changed: 412 ins; 114 del; 39 mod
Patch: https://git.openjdk.org/jdk/pull/19927.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/19927/head:pull/19927
PR: https://git.openjdk.org/jdk/pull/19927
More information about the core-libs-dev
mailing list