Use shifted-elements optimization for splice

RESOLVED FIXED in Firefox 55

Status

()

enhancement
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: jandem, Assigned: jandem)

Tracking

unspecified
mozilla55
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox55 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

2 years 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

2 years ago
Flags: needinfo?(jdemooij)
(Assignee)

Comment 1

2 years 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

2 years ago
Posted patch PatchSplinter Review
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 on attachment 8869706 [details] [diff] [review]
Patch

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

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

Comment 4

2 years 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

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