RFR: 8336856: Optimize String Concat

Shaojin Wen duke at openjdk.org
Sun Jul 21 12:46:34 UTC 2024


On Sun, 21 Jul 2024 12:25:36 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

Here are the performance numbers running on a MacBook M1 Pro, In the scenario of concat two ints, such as `StringConcat.concatConstIntConstInt`, the performance is improved by 10.98%

-Benchmark                            (intValue)  Mode  Cnt   Score   Error  Units (master c25c4896ad9ef031e3cddec493aef66ff87c48a7)
-StringConcat.concatConstInt                4711  avgt   15   6.283 ? 0.007  ns/op
-StringConcat.concatConstIntConstInt        4711  avgt   15  15.164 ? 0.428  ns/op

+Benchmark                            (intValue)  Mode  Cnt   Score   Error  Units ( 227158a7879023cf495c8f1e3704d7e665fcb3bb )
+StringConcat.concatConstInt                4711  avgt   15   6.115 ? 0.062  ns/op +2.74%
+StringConcat.concatConstIntConstInt        4711  avgt   15  13.663 ? 0.413  ns/op +10.98%

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

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


More information about the core-libs-dev mailing list