Closed Bug 1522157 Opened 7 months ago Closed 7 months ago

Add fast path when TypedArray.from is called with arrays


(Core :: JavaScript Engine, enhancement)

Not set



Tracking Status
firefox66 --- wontfix
firefox67 --- fixed


(Reporter: anba, Assigned: anba)




(2 files)

bug 1491813 will need some helpers to detect built-in TypedArray constructors and an unchanged 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]

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

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

Pushed by
Part 1: Add fast path when TypedArray.from is called with packed arrays. r=jandem
Part 2: Inline IsTypedArrayConstructor with a constant if possible. r=jandem

Keywords: checkin-needed
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.