Use shifted-elements optimization for splice

RESOLVED FIXED in Firefox 55

Status

()

Core
JavaScript Engine
RESOLVED FIXED
3 months ago
3 months ago

People

(Reporter: jandem, Assigned: jandem)

Tracking

unspecified
mozilla55
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox55 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

3 months ago
The shifted-elements optimization added for bug 1348772 can be used for splice too, when deleting elements from the start of the array: arr.splice(0, x). This is pretty common, some grepping shows a few benchmarks like Octane-pdfjs do this.
(Assignee)

Updated

3 months ago
Flags: needinfo?(jdemooij)
(Assignee)

Comment 1

3 months ago
This should be straight-forward, but I'll wait for bug 1362753 to land to avoid merge conflicts for one of us :)
Depends on: 1362753
(Assignee)

Comment 2

3 months ago
Created attachment 8869706 [details] [diff] [review]
Patch

We now call tryShiftDenseElements when splice is shrinking the array.

When calling arr.splice(0, 2) on an array with 50,000 elements, until the array is empty, I get the following:

Chrome:        5 ms
Safari:      163 ms
Nightly old: 484 ms
Nightly new:   5 ms

Like with shift(), Chrome has a perf cliff around 50k elements. For instance when there are 80,000 elements:

Chrome:      1264 ms
Safari:       447 ms
Nightly old: 1275 ms
Nightly new:    9 ms

I added some logging and this optimization hits pretty often on the web, and it seems useful to have in case people are relying on V8's fast path.
Assignee: nobody → jdemooij
Status: NEW → ASSIGNED
Flags: needinfo?(jdemooij)
Attachment #8869706 - Flags: review?(andrebargull)

Comment 3

3 months ago
Comment on attachment 8869706 [details] [diff] [review]
Patch

Review of attachment 8869706 [details] [diff] [review]:
-----------------------------------------------------------------

Great results!
Attachment #8869706 - Flags: review?(andrebargull) → review+

Comment 4

3 months ago
Pushed by jandemooij@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/fe4dbfcf9328
Optimize splice to shift the elements header when deleting from the start of the array. r=anba

Comment 5

3 months ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/fe4dbfcf9328
Status: ASSIGNED → RESOLVED
Last Resolved: 3 months ago
status-firefox55: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.