Closed Bug 1457256 Opened 7 years ago Closed 6 years ago

TypedArray.prototype.slice is 3x slower than subarray + set

Categories

(Core :: JavaScript Engine, defect, P2)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1140152
Tracking Status
firefox61 --- affected

People

(Reporter: mstange, Unassigned)

References

Details

Attachments

(1 file)

Attached file testcase
If I have a large Uint8Array and want to copy out a part of it into a new Uint8Array, there is a large performance difference depending on how you do it: function sliceUsingSlice(originalArray, offset, len) { return originalArray.slice(offset, len); } function sliceUsingSubarrayAndSet(originalArray, offset, len) { const slice = new Uint8Array(len); slice.set(originalArray.subarray(offset, len)); return slice; } On a 100MB array, I get times around 250ms on the first and ~75ms on the second. It looks slice implements the actual copying in self-hosted JS code, so it might be the bounds checks that are hurting us. > // Step 14.b. > while (k < final) { > // Steps 14.b.i-v. > A[n++] = O[k++]; > }
With the patch attached to bug 1140152 both functions need about the same time for me.
Depends on: 1140152
Priority: -- → P2
The issue should be fixed by bug 1140152, but if you still see any major performance differences please reopen. Thanks!
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
Can confirm. Thanks!
\o/ Thanks for confirming!
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: