RFR: 8337282: Speed up StringConcat with more simpleConcat
Shaojin Wen
duke at openjdk.org
Fri Jul 26 16:13:30 UTC 2024
On Fri, 26 Jul 2024 15:56:14 GMT, Shaojin Wen <duke at openjdk.org> wrote:
> StringConcatFactory improves startup speed and running performance through simpleConcat, but simpleConcat is currently given priority and only supports the following scenarios:
>
> // x instanceof Object
> prefix + x
> x = subfix
>
> // x instanceof Object && z instanceof Object
> x + y
>
>
> This PR improves startup and running performance by supporting more scenarios including
>
> // x instanceof byte/short/int/char/boolean/float/double
> prefix + x
> x + suffix
>
> // x instanceof byte/short/int/char/boolean/float/double/Integer/Long/Object
> prefix + suffix
>
> // x instanceof Object
> x + y + suffix
>
> // x instanceof Object
> x + y + suffix
Below are the performance numbers running on MacBook M1 Pro
-# baseline 5ff7c57f9ff5428ef3d2aedd7e860bb1e8ff29ea
-Benchmark (intValue) Mode Cnt Score Error Units
-StringConcat.concat123String 4711 avgt 15 989.444 ? 2.359 ns/op
-StringConcat.concat13String 4711 avgt 15 45.880 ? 0.316 ns/op
-StringConcat.concat23String 4711 avgt 15 90.688 ? 0.336 ns/op
-StringConcat.concat23StringConst 4711 avgt 15 99.499 ? 0.165 ns/op
-StringConcat.concat3String 4711 avgt 15 12.203 ? 0.178 ns/op
-StringConcat.concat4String 4711 avgt 15 13.916 ? 0.163 ns/op
-StringConcat.concat6String 4711 avgt 15 19.490 ? 0.368 ns/op
-StringConcat.concatConst2String 4711 avgt 15 9.440 ? 0.093 ns/op
-StringConcat.concatConst4String 4711 avgt 15 17.013 ? 3.545 ns/op
-StringConcat.concatConst6Object 4711 avgt 15 50.599 ? 0.182 ns/op
-StringConcat.concatConst6String 4711 avgt 15 19.641 ? 0.177 ns/op
-StringConcat.concatConstBoolByte 4711 avgt 15 6.417 ? 0.028 ns/op
-StringConcat.concatConstBooleanString 4711 avgt 15 7.022 ? 0.025 ns/op
-StringConcat.concatConstFloat 4711 avgt 15 56.320 ? 1.348 ns/op
-StringConcat.concatConstFloatString 4711 avgt 15 60.025 ? 1.879 ns/op
-StringConcat.concatConstInt 4711 avgt 15 6.076 ? 0.037 ns/op
-StringConcat.concatConstIntConstInt 4711 avgt 15 9.730 ? 0.151 ns/op
-StringConcat.concatConstIntString 4711 avgt 15 14.339 ? 0.187 ns/op
-StringConcat.concatConstInteger 4711 avgt 15 3.991 ? 0.024 ns/op
-StringConcat.concatConstIntegerString 4711 avgt 15 6.895 ? 0.031 ns/op
-StringConcat.concatConstString 4711 avgt 15 4.958 ? 0.021 ns/op
-StringConcat.concatConstStringConstInt 4711 avgt 15 11.135 ? 1.184 ns/op
-StringConcat.concatEmptyConstInt 4711 avgt 15 5.631 ? 0.066 ns/op
-StringConcat.concatEmptyConstString 4711 avgt 15 2.019 ? 0.002 ns/op
-StringConcat.concatEmptyLeft 4711 avgt 15 2.215 ? 0.017 ns/op
-StringConcat.concatEmptyRight 4711 avgt 15 2.387 ? 0.058 ns/op
-StringConcat.concatMethodConstString 4711 avgt 15 4.972 ? 0.014 ns/op
-StringConcat.concatMix4String 4711 avgt 15 80.159 ? 2.225 ns/op
-StringConcat.concatStringIntString 4711 avgt 15 18.138 ? 0.428 ns/op
-StringConcat.concatStringIntegerString 4711 avgt 15 9.031 ? 0.034 ns/op
-StringConcatStartup.MixedLarge.run N/A ss 10 310.643 ? 9.422 ms/op
-StringConcatStartup.MixedSmall.run N/A ss 20 24.493 ? 0.583 ms/op
-StringConcatStartup.StringLarge.run N/A ss 10 86.554 ? 3.910 ms/op
-StringConcatStartup.StringSingle.constBooleanString 4711 ss 40 0.261 ? 0.010 ms/op
-StringConcatStartup.StringSingle.constFloat 4711 ss 40 2.580 ? 0.083 ms/op
-StringConcatStartup.StringSingle.constFloatString 4711 ss 40 4.465 ? 0.115 ms/op
-StringConcatStartup.StringSingle.constInt 4711 ss 40 2.056 ? 0.056 ms/op
-StringConcatStartup.StringSingle.constIntString 4711 ss 40 0.159 ? 0.009 ms/op
-StringConcatStartup.StringSingle.constInteger 4711 ss 40 0.140 ? 0.008 ms/op
-StringConcatStartup.StringSingle.constIntegerString 4711 ss 40 3.522 ? 0.080 ms/op
-StringConcatStartup.StringSingle.constString 4711 ss 40 0.138 ? 0.010 ms/op
-StringConcatStartup.StringThree.stringIntString 4711 ss 40 6.051 ? 0.156 ms/op
-StringConcatStartup.StringThree.stringIntegerString 4711 ss 40 5.115 ? 0.166 ms/op
+# current 37f42b1065663337acd2d91a40e0a34010ebcfa3
+Benchmark (intValue) Mode Cnt Score Error Units
+StringConcat.concat123String 4711 avgt 15 992.155 ? 7.624 ns/op
+StringConcat.concat13String 4711 avgt 15 45.763 ? 0.156 ns/op
+StringConcat.concat23String 4711 avgt 15 90.949 ? 0.508 ns/op
+StringConcat.concat23StringConst 4711 avgt 15 99.758 ? 0.517 ns/op
+StringConcat.concat3String 4711 avgt 15 12.564 ? 0.303 ns/op
+StringConcat.concat4String 4711 avgt 15 13.827 ? 0.129 ns/op
+StringConcat.concat6String 4711 avgt 15 19.679 ? 0.372 ns/op
+StringConcat.concatConst2String 4711 avgt 15 7.233 ? 0.038 ns/op
+StringConcat.concatConst4String 4711 avgt 15 14.763 ? 0.077 ns/op
+StringConcat.concatConst6Object 4711 avgt 15 50.771 ? 0.206 ns/op
+StringConcat.concatConst6String 4711 avgt 15 19.565 ? 0.102 ns/op
+StringConcat.concatConstBoolByte 4711 avgt 15 6.412 ? 0.008 ns/op
+StringConcat.concatConstBooleanString 4711 avgt 15 5.259 ? 0.009 ns/op
+StringConcat.concatConstFloat 4711 avgt 15 53.374 ? 0.755 ns/op
+StringConcat.concatConstFloatString 4711 avgt 15 61.902 ? 2.410 ns/op
+StringConcat.concatConstInt 4711 avgt 15 4.955 ? 0.017 ns/op
+StringConcat.concatConstIntConstInt 4711 avgt 15 9.742 ? 0.141 ns/op
+StringConcat.concatConstIntString 4711 avgt 15 8.284 ? 0.027 ns/op
+StringConcat.concatConstInteger 4711 avgt 15 3.996 ? 0.016 ns/op
+StringConcat.concatConstIntegerString 4711 avgt 15 5.942 ? 0.098 ns/op
+StringConcat.concatConstString 4711 avgt 15 4.972 ? 0.018 ns/op
+StringConcat.concatConstStringConstInt 4711 avgt 15 11.326 ? 1.466 ns/op
+StringConcat.concatEmptyConstInt 4711 avgt 15 5.600 ? 0.025 ns/op
+StringConcat.concatEmptyConstString 4711 avgt 15 2.043 ? 0.031 ns/op
+StringConcat.concatEmptyLeft 4711 avgt 15 2.242 ? 0.030 ns/op
+StringConcat.concatEmptyRight 4711 avgt 15 2.356 ? 0.035 ns/op
+StringConcat.concatMethodConstString 4711 avgt 15 4.969 ? 0.016 ns/op
+StringConcat.concatMix4String 4711 avgt 15 80.263 ? 2.323 ns/op
+StringConcat.concatStringIntString 4711 avgt 15 18.328 ? 0.411 ns/op
+StringConcat.concatStringIntegerString 4711 avgt 15 9.019 ? 0.025 ns/op
+StringConcatStartup.MixedLarge.run N/A ss 10 317.535 ? 20.464 ms/op
+StringConcatStartup.MixedSmall.run N/A ss 20 24.886 ? 0.607 ms/op
+StringConcatStartup.StringLarge.run N/A ss 10 85.655 ? 3.967 ms/op
+StringConcatStartup.StringSingle.constBooleanString 4711 ss 40 0.575 ? 0.021 ms/op
+StringConcatStartup.StringSingle.constFloat 4711 ss 40 1.035 ? 0.038 ms/op
+StringConcatStartup.StringSingle.constFloatString 4711 ss 40 0.747 ? 0.023 ms/op
+StringConcatStartup.StringSingle.constInt 4711 ss 40 0.844 ? 0.030 ms/op
+StringConcatStartup.StringSingle.constIntString 4711 ss 40 0.559 ? 0.020 ms/op
+StringConcatStartup.StringSingle.constInteger 4711 ss 40 0.154 ? 0.013 ms/op
+StringConcatStartup.StringSingle.constIntegerString 4711 ss 40 0.438 ? 0.017 ms/op
+StringConcatStartup.StringSingle.constString 4711 ss 40 0.149 ? 0.010 ms/op
+StringConcatStartup.StringThree.stringIntString 4711 ss 40 5.995 ? 0.140 ms/op
+StringConcatStartup.StringThree.stringIntegerString 4711 ss 40 5.295 ? 0.112 ms/op
| | baseline | current | delta |
| --- | --- | --- | --- |
| StringConcat.concat123String | 989.444 | 992.155 | -0.27% |
| StringConcat.concat13String | 45.880 | 45.763 | 0.26% |
| StringConcat.concat23String | 90.688 | 90.949 | -0.29% |
| StringConcat.concat23StringConst | 99.499 | 99.758 | -0.26% |
| StringConcat.concat3String | 12.203 | 12.564 | -2.87% |
| StringConcat.concat4String | 13.916 | 13.827 | 0.64% |
| StringConcat.concat6String | 19.490 | 19.679 | -0.96% |
| StringConcat.concatConst2String | 9.440 | 7.233 | 30.51% |
| StringConcat.concatConst4String | 17.013 | 14.763 | 15.24% |
| StringConcat.concatConst6Object | 50.599 | 50.771 | -0.34% |
| StringConcat.concatConst6String | 19.641 | 19.565 | 0.39% |
| StringConcat.concatConstBoolByte | 6.417 | 6.412 | 0.08% |
| StringConcat.concatConstBooleanString | 7.022 | 5.259 | 33.52% |
| StringConcat.concatConstFloat | 56.320 | 53.374 | 5.52% |
| StringConcat.concatConstFloatString | 60.025 | 61.902 | -3.03% |
| StringConcat.concatConstInt | 6.076 | 4.955 | 22.62% |
| StringConcat.concatConstIntConstInt | 9.730 | 9.742 | -0.12% |
| StringConcat.concatConstIntString | 14.339 | 8.284 | 73.09% |
| StringConcat.concatConstInteger | 3.991 | 3.996 | -0.13% |
| StringConcat.concatConstIntegerString | 6.895 | 5.942 | 16.04% |
| StringConcat.concatConstString | 4.958 | 4.972 | -0.28% |
| StringConcat.concatConstStringConstInt | 11.135 | 11.326 | -1.69% |
| StringConcat.concatEmptyConstInt | 5.631 | 5.600 | 0.55% |
| StringConcat.concatEmptyConstString | 2.019 | 2.043 | -1.17% |
| StringConcat.concatEmptyLeft | 2.215 | 2.242 | -1.20% |
| StringConcat.concatEmptyRight | 2.387 | 2.356 | 1.32% |
| StringConcat.concatMethodConstString | 4.972 | 4.969 | 0.06% |
| StringConcat.concatMix4String | 80.159 | 80.263 | -0.13% |
| StringConcat.concatStringIntString | 18.138 | 18.328 | -1.04% |
| StringConcat.concatStringIntegerString | 9.031 | 9.019 | 0.13% |
| StringConcatStartup.MixedLarge.run | 310.643 | 317.535 | -2.17% |
| StringConcatStartup.MixedSmall.run | 24.493 | 24.886 | -1.58% |
| StringConcatStartup.StringLarge.run | 86.554 | 85.655 | 1.05% |
| StringConcatStartup.StringSingle.constBooleanString | 0.261 | 0.575 | -54.61% |
| StringConcatStartup.StringSingle.constFloat | 2.580 | 1.035 | 149.28% |
| StringConcatStartup.StringSingle.constFloatString | 4.465 | 0.747 | 497.72% |
| StringConcatStartup.StringSingle.constInt | 2.056 | 0.844 | 143.60% |
| StringConcatStartup.StringSingle.constIntString | 0.159 | 0.559 | -71.56% |
| StringConcatStartup.StringSingle.constInteger | 0.140 | 0.154 | -9.09% |
| StringConcatStartup.StringSingle.constIntegerString | 3.522 | 0.438 | 704.11% |
| StringConcatStartup.StringSingle.constString | 0.138 | 0.149 | -7.38% |
| StringConcatStartup.StringThree.stringIntString | 6.051 | 5.995 | 0.93% |
| StringConcatStartup.StringThree.stringIntegerString | 5.115 | 5.295 | -3.40% |
* Scenarios with Significantly Improved Running Performance
| | baseline | current | delta |
| --- | --- | --- | --- |
| StringConcat.concatConst2String | 9.440 | 7.233 | 30.51% |
| StringConcat.concatConstBooleanString | 7.022 | 5.259 | 33.52% |
| StringConcat.concatConstInt | 6.076 | 4.955 | 22.62% |
| StringConcat.concatConstIntString | 14.339 | 8.284 | 73.09% |
| StringConcat.concatConstIntegerString | 6.895 | 5.942 | 16.04% |
* Startup performance significantly improved
| | baseline | current | delta |
| --- | --- | --- | --- |
| StringConcatStartup.StringSingle.constFloat | 2.580 | 1.035 | 149.28% |
| StringConcatStartup.StringSingle.constFloatString | 4.465 | 0.747 | 497.72% |
| StringConcatStartup.StringSingle.constInt | 2.056 | 0.844 | 143.60% |
| StringConcatStartup.StringSingle.constIntegerString | 3.522 | 0.438 | 704.11% |
-------------
PR Comment: https://git.openjdk.org/jdk/pull/20355#issuecomment-2253071979
More information about the core-libs-dev
mailing list