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)
Core
JavaScript Engine
Tracking
()
RESOLVED
DUPLICATE
of bug 1140152
Tracking | Status | |
---|---|---|
firefox61 | --- | affected |
People
(Reporter: mstange, Unassigned)
References
Details
Attachments
(1 file)
1.92 KB,
text/html
|
Details |
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++];
> }
Comment 1•7 years ago
|
||
With the patch attached to bug 1140152 both functions need about the same time for me.
Depends on: 1140152
Updated•7 years ago
|
Priority: -- → P2
Comment 2•6 years ago
|
||
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
Reporter | ||
Comment 3•6 years ago
|
||
Can confirm. Thanks!
Comment 4•6 years ago
|
||
\o/
Thanks for confirming!
You need to log in
before you can comment on or make changes to this bug.
Description
•