| Summary: | String.concat() significantly slower than '+' operator | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Nicholas Shanks <nickshanks> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW --- | ||
| Severity: | Normal | CC: | fpizlo, keith_miller, webkit-bug-importer, ysuzuki |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 11 | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
|
Description
Nicholas Shanks
2018-08-23 04:23:27 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. |