Inline iterator code into Map/Set.prototype.forEach

RESOLVED FIXED in Firefox 56

Status

()

enhancement
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: anba, Assigned: anba)

Tracking

Trunk
mozilla56
Points:
---

Firefox Tracking Flags

(firefox56 fixed)

Details

Attachments

(1 attachment, 1 obsolete attachment)

With bug 1380087, this patch seems to improve Map.prototype.forEach quite a bit.


Improves from 480ms (tip) to 150ms:

    var m = new Map(Array(100).fill(0).map((v, k) => [k + 1, null]));
    var q = 0;
    function fn(v, k) { q += k; }
    var t = Date.now();
    for (var i = 0; i < 100000; ++i) {
        m.forEach(fn);
    }
    print([Date.now() - t, q);



Improves from 160ms (bug 1380087) to 130ms for me:

    var s = new Set(Array(100).fill(0).map((v, k) => k + 1));
    var q = 0;
    function fn() { ++q; }
    var t = Date.now();
    for (var i = 0; i < 100000; ++i) {
        s.forEach(fn);
    }
    print(Date.now() - t, q);
Posted patch bug1380111.patch (obsolete) — Splinter Review
Attachment #8885418 - Flags: review?(till)
Comment on attachment 8885418 [details] [diff] [review]
bug1380111.patch

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

Nice, r=me

::: js/src/builtin/Set.js
@@ +37,5 @@
>      var values = callFunction(std_Set_iterator, S);
> +
> +    // Inlined: SetIteratorNext
> +    var setIterationResult = setIteratorTemp.setIterationResult;
> +    if (!setIterationResult) {

style nit: no braces needed
Attachment #8885418 - Flags: review?(till) → review+
Addressed review comments, carrying r+.
Attachment #8885418 - Attachment is obsolete: true
Attachment #8885835 - Flags: review+
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/bed95eec1188
Inline iterator code into Map/Set forEach to avoid extra allocations. r=till
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/bed95eec1188
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.