NEW 188882
String.concat() significantly slower than '+' operator
https://bugs.webkit.org/show_bug.cgi?id=188882
Summary String.concat() significantly slower than '+' operator
Nicholas Shanks
Reported 2018-08-23 04:23:27 PDT
When String.prototype.concat() and String.prototype.join() have not been modified from their initial values, promotion of their arguments to strings and concatenation of those strings should be nearly as fast as the '+' operator with one string operand (which also has to promote the other operand). This will allow functional composition to be performant. See https://jsperf.com/concat-vs-plus-vs-join-2
Attachments
Radar WebKit Bug Importer
Comment 1 2018-08-23 09:46:38 PDT
Keith Miller
Comment 2 2018-08-27 02:12:12 PDT
It looks like you are seeing such a large difference because the test is passing more than one argument to concat at the same time. This causes us to emit a loop which is slowing that code down. If you change your test to: string1.concat(string2).concat(string3); you will see that the perf is quite close. In theory we could do some loop unrolling to fix this but the same issue applies to calling the '+' operator in a loop. The join case is slow because it will allocate an Array, which is expensive. We could also optimize this but it's probably easier to use the concat method for now.
Note You need to log in before you can comment on or make changes to this bug.