Closed Bug 1366372 Opened 8 years ago Closed 8 years ago

Array.from is way too slow

Categories

(Core :: JavaScript: Standard Library, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: anba, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

test case: --- function zeroElements() { var a = []; var t = Date.now(); for (var i = 0; i < 1000000; ++i) Array.from(a); print(Date.now() - t); } function tenElements() { var a = [1,2,3,4,5,6,7,8,9,10]; var t = Date.now(); for (var i = 0; i < 1000000; ++i) Array.from(a); print(Date.now() - t); } zeroElements(); tenElements(); --- Expected: - zeroElements() completes in 200ms in my dev-environment - tenElements() completes in 380ms in my dev-environment Actual: - zeroElements() needs 4000ms - tenElements() needs 4800ms Patch forthcoming... :-)
Attached patch bug1366372.patchSplinter Review
Function default parameters combined with nested functions are a real show-stopper. Inferred functions names are also slow when they need to be computed at runtime. I've also removed the inlined version of IterableToList in TypedArrayStaticFrom, because it's no longer needed and the new IterableToList function is actually faster (Arrays + DefineDataProperty perform now better than the self-hosted List version). And for another few 100ms, I've removed the arguments check from GetIterator. We're now always calling GetIterator with two arguments, so we don't need to have this check any longer.
Attachment #8869567 - Flags: review?(evilpies)
Comment on attachment 8869567 [details] [diff] [review] bug1366372.patch Review of attachment 8869567 [details] [diff] [review]: ----------------------------------------------------------------- Ah so before we got an abort in Array.from with "has extra var environment" and in GetIterator with "NYI: arguments & setarg.". Pretty bad, seems like it would be trivial to run into that again. Thanks for fixing this!
Attachment #8869567 - Flags: review?(evilpies) → review+
(In reply to Tom Schuster [:evilpie] from comment #2) > Ah so before we got an abort in Array.from with "has extra var environment" > and in GetIterator with "NYI: arguments & setarg.". Pretty bad, seems like > it would be trivial to run into that again. Thanks for fixing this! Thanks for investigating and filing bug 1366470!
Pushed by ryanvm@gmail.com: https://hg.mozilla.org/integration/autoland/rev/9dd114fb1542 Remove performance pitfalls in Array.from method. r=evilpie
Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: