My addons do a metric tonne of string concatenation, and I'm looking to optimize this as much as possible. I've read that each use of ".." causes a new string to be made, and each new string will need to be garbage collected. So ".." is bad if used everywhere.
My current thinking is to replace any string that is the product of more than a single ".." with a call to "strjoin()" with an empty string as the delimiter.
Is this correct? Or would "strjoin()" (is this a call to native C/C++?) end up being more expensive in the long run than generating all that extra work for Lua's memory management?
lua will treat consecutive concatenation in the same expression as a single operation, and will only internalize the result of the full concatenation:
Will only internalize the string "Hello, world!" which may need to be collected later on.
So, in most cases, it's not useful to replace this expression by a call to strjoin().
What should be avoided is code like "a = a .. b" in loops. And even then, it strictly depends on the size of the string and the number of time the loop is executed to determine if using a temporary table is better.