resourceloader: Optimise getCombinedVersion() with string concat
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 14 Aug 2018 00:39:45 +0000 (01:39 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 14 Aug 2018 00:40:17 +0000 (00:40 +0000)
commit42bc7942038fe4c5f103edab00e6a8203a96f378
tree205389016b3feeee95bc326ba133e8245a328b49
parent6815e355753c633578636d6b3102f70f4038a602
resourceloader: Optimise getCombinedVersion() with string concat

This is used many times in the hot path. The main motivation for
this is to reduce memory churn in that path.

By building up a string directly instead of first mapping into an
array, and than using Array#join() - we avoid some of that churn.

It terms of speed, avoiding Array#join resulted in the same
or better performance for the browsers I tested.

|                | Chrome 60     | Safari 11.1   | Firefox 61
| map+join       | 241K/s (± 2%) | 189K/s (± 5%) | 161K/s (± 6%)
| forEach+concat | 297K/s (± 1%) | 398K/s (± 2%) | 159K/s (± 13%)
| reduce         | 437K/s (± 2%) | 396K/s (± 1%) | 138K/s (± 12%)

For Chrome and Safari, 'reduce' were marked "fastest".
For Firefox, JSPerf marked all three as fastest due to the
variable ranges overlapping. Re-runs produced similar results,
each time with three cases laid out in a slightly different order
in the 130-165K/s range. The test used a copy of en.wikipedia's
current registry with the module queue of a random article.
https://jsperf.com/array-map-and-join-vs-string-concat/1

Change-Id: Ifbd8f6509ac118657c5ad2833f54fd6e8e63f9ce
resources/src/startup/mediawiki.js