Closed Bug 1522157 Opened 7 months ago Closed 7 months ago

Add fast path when TypedArray.from is called with arrays

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set

Tracking

()

RESOLVED FIXED
mozilla67
Tracking Status
firefox66 --- wontfix
firefox67 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(2 files)

bug 1491813 will need some helpers to detect built-in TypedArray constructors and an unchanged %ArrayIteratorPrototype%.next property. These two helpers can also be used to optimise the case when TypedArray.from(...) is called with normal arrays. So let's do this first here to unblock the work on bug 1491813.

Adds a fast path when TypedArray.from is called with a packed array.

The fast path can be applied when the following conditions hold:

  • There is no mapper function which could modify the input array during the iteration.
  • The constructor is a built-in TypedArray constructor.
  • The iterator function is the builtin Array.prototype[Symbol.iterator] function ArrayValues.
  • The array itself is a packed array.
  • And finally ArrayIteratorPrototype is still in its initial state.

This optimisation allows to omit creating a temporary list in IterableToList and instead directly fill the TypedArray elements from the input array using the existing ElementSpecific<T, UnsharedOps>::initFromIterablePackedArray function.

Drive-by change:

  • Change ForOfPIC::createForOfPICObject to directly create a tenured object, because this object is created once and then stored indefinitely in the global object.
  • Make some ForOfPIC methods private.

The IsTypedArrayConstructor and ArrayIteratorPrototypeOptimizable helpers will also be necessary in bug 1491813.

Attachment #9040504 - Flags: review?(jdemooij)

Allow to replace the IsTypedArrayConstructor call with a constant when the function is always called with TypedArray constructor functions.

Attachment #9040505 - Flags: review?(jdemooij)

I also have a patch to inline ArrayIteratorPrototypeOptimizable, but since I'm not quite sure about possible gc-barrier interactions I need to be aware of when reading GCPtr<> fields directly from assembler code, I'd like to defer that part for now.

Attachment #9040505 - Flags: review?(jdemooij) → review+
Comment on attachment 9040504 [details] [diff] [review]
bug1522157-part1-fastpath-for-packedarray.patch

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

LGTM!
Attachment #9040504 - Flags: review?(jdemooij) → review+

Pushed by nerli@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/d58a5867916b
Part 1: Add fast path when TypedArray.from is called with packed arrays. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/f801cbd96efc
Part 2: Inline IsTypedArrayConstructor with a constant if possible. r=jandem

Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
Depends on: 1524943
You need to log in before you can comment on or make changes to this bug.