Optimize NativeObject::addEnumerableDataProperty

RESOLVED FIXED in Firefox 59

Status

()

defect
P3
normal
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: jandem, Assigned: jandem)

Tracking

(Blocks 1 bug)

unspecified
mozilla59
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox59 fixed)

Details

Attachments

(1 attachment)

Assignee

Description

2 years ago
Posted patch PatchSplinter Review
addEnumerableDataProperty is one of the hottest functions on Speedometer and adding new properties to objects is still slower than it should be.

The attached patch adds a fast path to addEnumerableDataProperty for non-dictionary objects that have a single kid shape that matches the new property. This fast path hits most of the time on both Octane and Speedometer.

For the micro-benchmark below I get the following, best of 5 runs:

before: 945 ms
after:  811 ms

It also improves six-speed's object-assign-es6 test from 237 ms to 208 ms.

There's more to optimize here but this is a good start.

function g(a) {
    var o = {};
    for (var i = 0; i < a.length; i++) {
        o[a[i]] = i;
    }
    return o;
}
function f() {
    var arr = ["a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"];
    var t = new Date;
    for (var i = 0; i < 1000000; i++)
        res = g(arr);
    print(new Date - t);
}
f();
Attachment #8934135 - Flags: review?(bhackett1024)
Assignee

Comment 1

2 years ago
Oops, that micro-benchmark is wrong, the numbers are for this slightly simpler one:

function f() {
    var arr = ["a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"];
    var t = new Date;
    for (var i = 0; i < 1000000; i++) {
        res = {};
        for (var j = 0; j < arr.length; j++) {
            res[arr[j]] = i;
        }
    }
    print(new Date - t);
}
f();
Attachment #8934135 - Flags: review?(bhackett1024) → review+

Comment 2

2 years ago
Pushed by jandemooij@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/10aa5c0593fa
Optimize addEnumerableDataProperty by adding a fast path for the most common case. r=bhackett
Priority: -- → P3

Comment 3

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