Closed Bug 1381469 Opened 7 years ago Closed 7 years ago

Improve TypedArray iteration by avoid the detached buffer check when the current length is non-zero

Categories

(Core :: JavaScript: Standard Library, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file)

It's faster to call PossiblyWrappedTypedArrayLength (because it can be inlined), than to call PossiblyWrappedTypedArrayHasDetachedBuffer (which isn't inlined). So to speed up typed array iteration, we can avoid calling PossiblyWrappedTypedArrayHasDetachedBuffer when the current typed array length is non-zero (we currently reset the length to zero when the underlying array buffer was detached, so any typed array with a non-zero length can't have a detached array buffer).


Improves this µ-benchmark from 240ms to 50ms for me:

    var a = new Int32Array(100).map((v, k) => k + 1);
    var q = 0;
    var t = Date.now();
    for (var i = 0; i < 100000; ++i) {
        for (var x of a) q += x;
    }
    print(Date.now() - t, q);
Attached patch bug1381469.patchSplinter Review
This avoids the slow PossiblyWrappedTypedArrayHasDetachedBuffer check when the typed array is definitely not detached.
Attachment #8887030 - Flags: review?(till)
Comment on attachment 8887030 [details] [diff] [review]
bug1381469.patch

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

nice, r=me
Attachment #8887030 - Flags: review?(till) → review+
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/75e1e435c2b6
Only check for detached buffers when iterating over typed arrays when the current length is zero. r=till
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/75e1e435c2b6
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: