RFR: 8336856: Optimize String Concat [v11]

Shaojin Wen duke at openjdk.org
Wed Jul 24 14:31:37 UTC 2024


On Wed, 24 Jul 2024 11:43:45 GMT, Shaojin Wen <duke at openjdk.org> wrote:

>> The current implementation of StringConcat is to mix the coder and length into a long. This operation will have some overhead for int/long/boolean types. We can separate the calculation of the coder from the calculation of the length, which can improve the performance in the scenario of concat int/long/boolean.
>> 
>> This idea comes from the suggestion of @l4es in the discussion of PR https://github.com/openjdk/jdk/pull/20253#issuecomment-2240412866
>
> Shaojin Wen has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 32 commits:
> 
>  - Merge remote-tracking branch 'upstream/master' into optim_concat_factory_202407
>  - typo
>  - change comments
>  - minor refactor
>  - minor refactor
>  - reduce change
>  - copyright
>  - reduce change
>  - refactor based on 8335182
>  - use Float.toString & Double.toString
>  - ... and 22 more: https://git.openjdk.org/jdk/compare/05d88de0...6faecfd7

Below are the performance values ​​running on a MacBook M1 Pro, with a significant improvement in startup performance.
`StringConcatStartup.StringSingle.run` has a performance regression due to an additional static FLAG. Remove the following code and the performance of this scenario is the same.

String generateInlineCopy = VM.getSavedProperty("java.lang.invoke.StringConcat.generateInlineCopy");
GENERATE_INLINE_COPY = generateInlineCopy != null ? "true".equalsIgnoreCase(generateInlineCopy) : true;



String generateInlineCopy = VM.getSavedProperty("java.lang.invoke.StringConcat.generateInlineCopy");
GENERATE_INLINE_COPY = generateInlineCopy != null ? "true".equalsIgnoreCase(generateInlineCopy) : true;



-# baseline (05d88de05e9b7814ecd5517aacd17f0feafdff3c)
-Benchmark                               (intValue)  Mode  Cnt    Score   Error  Units
-StringConcatStartup.MixedLarge.run             N/A    ss   10  314.191 ? 8.621  ms/op
-StringConcatStartup.MixedSmall.run             N/A    ss   20   24.906 ? 0.669  ms/op
-StringConcatStartup.StringLarge.run            N/A    ss   10   87.491 ? 3.760  ms/op
-StringConcatStartup.StringSingle.run           N/A    ss   40    0.096 ? 0.002  ms/op

+# current e497c954bd2d27334cbfabb7efa6841d0a5d9427
+Benchmark                               (intValue)  Mode  Cnt    Score   Error  Units
+StringConcatStartup.MixedLarge.run             N/A    ss   10  102.306 ? 3.709  ms/op
+StringConcatStartup.MixedSmall.run             N/A    ss   20    4.366 ? 0.109  ms/op
+StringConcatStartup.StringLarge.run            N/A    ss   10   44.109 ? 1.600  ms/op
+StringConcatStartup.StringSingle.run           N/A    ss   40    0.126 ? 0.008  ms/op



|   | baseline  | current | delta |
| --- | --- | --- | --- |
| StringConcatStartup.MixedLarge.run | 314.191 | 102.306 | 207.11% |
| StringConcatStartup.MixedSmall.run | 24.906 | 4.366 | 470.45% |
| StringConcatStartup.StringLarge.run | 87.491 | 44.109 | 98.35% |
| StringConcatStartup.StringSingle.run | 0.096 | 0.126 | -23.81% |

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

PR Comment: https://git.openjdk.org/jdk/pull/20273#issuecomment-2248148892


More information about the core-libs-dev mailing list