Open Bug 664784 Opened 13 years ago Updated 2 years ago

Iterators are very slow compared to doing a for loop on an array

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect

Tracking

()

People

(Reporter: bzbarsky, Unassigned)

Details

Attachments

(1 file)

Consider the attached testcase, which tests various ways of enumerating an array.  I get numbers like so:

Wrapped iterator took   147 ms
Iterator took            93 ms
Self-hosted foreach took 16 ms
Array.foreach took       16 ms
'for each' loop took     37 ms

I profiled the wrapped iterator case, and it looks like we spend:

 13% pushing and popping generator frames
 23% in js::Interpret called from js::RunScript called from SendToGenerator
 10% snapshotting for that inner iterator (?)
  5% in SendToGenerator
  3% in generator_op
  3% under pushInvokeArgs
  8% under js_GetMethod called from js_IteratorMore
  3% in js_IteratorMore itself
  9% in JM jitcode

and some smaller bits.

Basically, lots of slow stuff.  Given that chrome code is trying to use iterators, anything we can do to speed things up here?
Attached file Shell testcase
Attachment #539839 - Attachment mime type: application/x-javascript → text/plain
We haven't really focused on generator perf at all; as in, we don't compile JSOP_YIELD/JSOP_GENERATOR.  About equally important (for small generator bodies) I think would be building a generator IC akin to the Function.prototype.{call,apply} ICs.

I think those are the high-order perf bits, but we could do better by changing the stack layout so that generators don't copy so much state back and forth on each activation/deactivation.
Assignee: general → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: