The standard implementation of String.replace is VERY poor performance-wise.
See package kotlin.text, StringsJVM.kt:
public actual fun String.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): String = splitToSequence(oldValue, ignoreCase = ignoreCase).joinToString(separator = newValue)
The code is just horrible from a performance point of view.
If the string contains 50 times “Hello” and we want to replace it with “World”, the code above will create 51 strings and join them.
The number of unnecessary memory allocations and memory copy operations is killing performance!
What a pity that the standard library contains such poorly optimized code :(.
Replacing this code with something decent (for example similar to what is found in Java StringUtils.replace) made the string replacements in our web application an order of magnitude (10x) faster.
I hope you can do the same in the standard Kotlin library.