Closed Bug 714010 Opened 13 years ago Closed 12 years ago

Array.prototype.forEach much slower than on Chrome / other perf issues

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: robarnold, Unassigned)

References

Details

Attachments

(1 file)

Attached file Semi-reduced test case
I have some code for drawing a parallax starfield to a 2d canvas which is significantly slower in Firefox than Chrome (33ms vs 12ms). I found that removing my use of my 2d position objects and using a traditional for loop instead of Array.forEach with a simple closure restored performance to be comparable.
CC'ing Till. Do you think this bug can be close or are the forEach perf still that far away from Chrome's?
I can confirm that Array#forEach isn't causing any slowdown in this example, anymore.
Unfortunately, we're still much slower without the patch applied than with it.

This difference, however, is completely caused by the creation of instances of the Position constructor. If I insert the following code, we're exactly as fast as Chrome on my computer:

    var s = topleft;
    this.points.forEach(function (p) {
      s.x = p.x;
      s.y = p.y;
      s.add(topleft);
      s.add(offset2);
      if (Math.abs(s.x) > clipX || Math.abs(s.y) > clipY)
        return;
      ctx.fillRect(s.x, s.y, 1, 1);
    });

I don't know if we want to keep this bug for tracking how generational GC will improve this particular testcase. If not, it can be closed.
Since the reported issue was regarding forEach, I'm closing it.
@robarnold, if you think there are reasons other than use of .forEach that make your script too slow, feel free to open other bugs.
:-p forgot to close...
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: