Closed Bug 1364345 Opened 6 years ago Closed 6 years ago

Use shifted-elements optimization for splice

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

Details

Attachments

(1 file)

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.
Flags: needinfo?(jdemooij)
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
Attached 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+
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
https://hg.mozilla.org/mozilla-central/rev/fe4dbfcf9328
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.