On Fri, 12 Apr 2024 10:19:27 GMT, Claes Redestad <redes...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line >> 1430: >> >>> 1428: cb.new_(STRING_BUILDER); >>> 1429: cb.dup(); >>> 1430: cb.invokespecial(STRING_BUILDER, "<init>", >>> MethodTypeDesc.ofDescriptor("()V")); >> >> Would there be value in initializing to a larger capacity? Given the number >> of append calls, seems the default cap of 16 is unlikely to be sufficient. > > Possibly. I tried a few simple variants that initialized the `StringBuilder` > capacity at various guesses, such as sum of constant sizes + some factor > based on args, but across a diverse set of micros that gives both some wins > and some regressions. Getting the estimation just right is pretty tricky, > especially when size of the arguments are arbitrary (like for any > String/Object arg). What are the scenarios which had regressions? Given the conservative growth for StringBuilder, it surprises me a bit that any scenario would regress. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/18690#discussion_r1564165946