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

RESOLVED FIXED

Status

()

defect
RESOLVED FIXED
7 years ago
6 years ago

People

(Reporter: robarnold, Unassigned)

Tracking

Trunk
x86
macOS
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

7 years ago
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.
Duplicate of this bug: 598771

Comment 3

6 years ago
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.

Comment 5

6 years ago
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.

Comment 6

6 years ago
:-p forgot to close...
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.