RFR: 8265237: String.join and StringJoiner can be improved further

Peter Levart plevart at openjdk.java.net
Thu Apr 15 19:38:33 UTC 2021


On Wed, 14 Apr 2021 20:03:27 GMT, Claes Redestad <redestad at openjdk.org> wrote:

> There's a StringJoinerBenchmark micro added by JDK-8148937 which could perhaps be expanded with the scenarios you've experimented with here?

I modified that micro benchmark and added a method to also measure String.join static method along with StringJoiner for same parameters and extended the range of parameters to cover more diversity. The results are here:

https://jmh.morethan.io/?gist=c38cc13d63774ec505cc8d394c00d502

It is apparent that there is a huge speedup when strings are bigger. But even smaller strings get a substantial speedup. There's also substantial reduction of garbage per operation. Previously the garbage amounted to the internal array of String elements and the StringBuffer with its internal byte[] array of characters. Now only the array of elements is the garbage.

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

PR: https://git.openjdk.java.net/jdk/pull/3501


More information about the security-dev mailing list