String construction performance


Hi all !

I read one interesting article for String.concat for Oracle Java. Please see here (it is written on Russian, sorry); the same question on StackOverflow.

Short summary: chain append(x).append(y) of StringBuilder works faster than ordinal sb.append(x); sb.append(y) .

So, questions:

  • Does Kotlin have any tuning for this for inline string format (e.g. for “test, text, $myVariable, next text”)?
  • Does Kotlin have optinizations to convert developer’s code to JVM-friendly code (e.g. when dev. wrotes code in unoptimal way, Kotlin can do invisible speedup)?


Nice tip, have you reported in on YouTrack?


No, because this is just a question. I don’t know, how really it works. So, wating for JetBrains’s developers responce


Thanks for the heads up!
BTW, here’s the original blog post (in English):

We generate chained append calls for string templates ("blah ${expr} blah") and chained string concatenation (s1 + s2 + s3).

Currently - no, we don’t. I’ve created an issue in YT:


Added another issue for append call sequence to append call chain transformation:


Will methods be chained in apply body?



No. apply does not chain calls. They all go to sb.