Closed
Bug 1430800
Opened 6 years ago
Closed 6 years ago
Optimize String.raw by using arguments object instead of rest-arguments
Categories
(Core :: JavaScript: Standard Library, defect)
Core
JavaScript: Standard Library
Tracking
()
RESOLVED
FIXED
mozilla60
People
(Reporter: anba, Assigned: anba)
Details
Attachments
(1 file, 1 obsolete file)
4.59 KB,
patch
|
evilpie
:
review+
|
Details | Diff | Splinter Review |
Using the arguments object instead of rest-arguments seems to generate faster code when String.raw is called with substitutions. µ-benchmarks I've used for testing: (The String.raw calls always compute empty strings to avoid benchmarking string allocations. Hopefully this doesn't perturb the results in any way.) --- // zeroSubst: 20ms -> 20ms // oneSubst: 370ms -> 125ms // twoSubst: 450ms -> 215ms function zeroSubst() { var q = 0; var t = dateNow(); for (var i = 0; i < 10000000; ++i) { q += String.raw ``.length; } return [dateNow() - t, q]; } function oneSubst() { var xs = ["", ""]; var q = 0; var t = dateNow(); for (var i = 0; i < 10000000; ++i) { q += String.raw `${xs[i & 1]}`.length; } return [dateNow() - t, q]; } function twoSubst() { var q = 0; var t = dateNow(); for (var i = 0; i < 10000000; ++i) { q += String.raw `${xs[i & 1]}${xs[i & 1]}`.length; } return [dateNow() - t, q]; } ---
Assignee | ||
Updated•6 years ago
|
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Assignee | ||
Comment 1•6 years ago
|
||
Jan, do you think it's worthwhile to change the String.raw implementation to avoid rest-parameters or is there anything we can do in the JITs to achieve a similar performance improvement like with this patch?
Attachment #8942927 -
Flags: feedback?(jdemooij)
Comment 2•6 years ago
|
||
Comment on attachment 8942927 [details] [diff] [review] bug1430800.patch Review of attachment 8942927 [details] [diff] [review]: ----------------------------------------------------------------- Good find! Yeah this makes sense because we optimize |arguments| more than rest parameters atm.
Attachment #8942927 -
Flags: feedback?(jdemooij) → feedback+
Assignee | ||
Comment 3•6 years ago
|
||
This patch replaces the rest-parameter usage in String.raw with an arguments object based on the performance results in comment #0. I've also updated the step comments, changed the comparison in step 6 from |literalSegments <= 0| to |literalSegments === 0| (I'll create a spec PR to upstream this change), and added a special-case for |literalSegments === 1| to avoid a performance regression with the new code when String.raw is called with a single literal segment, i.e. String.raw `<literal>`.
Attachment #8942927 -
Attachment is obsolete: true
Attachment #8943612 -
Flags: review?(evilpies)
Comment 4•6 years ago
|
||
Comment on attachment 8943612 [details] [diff] [review] bug1430800.patch Review of attachment 8943612 [details] [diff] [review]: ----------------------------------------------------------------- Nice improvement
Attachment #8943612 -
Flags: review?(evilpies) → review+
Assignee | ||
Comment 5•6 years ago
|
||
Try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=d527eabf54c144d4fe059df6166529e2fec6c6c2
Keywords: checkin-needed
Pushed by rgurzau@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/1e5c359b9fe3 Optimize String.raw by avoiding rest-parameter array allocation. r=evilpie
Keywords: checkin-needed
Comment 7•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/1e5c359b9fe3
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
status-firefox60:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla60
Updated•6 years ago
|
You need to log in
before you can comment on or make changes to this bug.
Description
•