Closed Bug 1730699 Opened 3 years ago Closed 3 years ago

Optimize for-in with null/undefined better

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
94 Branch
Tracking Status
firefox94 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

(Blocks 2 open bugs)

Details

Attachments

(4 files)

for-in loops on null/undefined are somewhat common. Speedometer hits this too. We have some performance problems:

  • We allocate a new empty iterator for this each time, instead of reusing the same iterator object.
  • We don't have CacheIR support for this case. This can result in disabling the IC if this shows up a few times.

A patch stack to fix these issues improves the micro-benchmark below from 220 ms to 5 ms.

function f() {
  var t = new Date;
  for (var i = 0; i < 1_000_000; i++) {
    for (var p in undefined) {}
  }
  print(new Date - t);
}
f();

This changes the empty iterator objects we create for for-in with null/undefined
to be immutable and unlinked.

The next patch will cache this object on the global.

Pushed by jdemooij@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c7eae2ddd714
part 1 - Treat empty iterators for null/undefined as immutable and unlinked. r=jonco
https://hg.mozilla.org/integration/autoland/rev/cab0e02d59e1
part 2 - Cache empty iterator on the global. r=jonco
https://hg.mozilla.org/integration/autoland/rev/48465af484b5
part 3 - Clean up CacheIR code for GetIterator a bit. r=jonco
https://hg.mozilla.org/integration/autoland/rev/8a9d97b273e7
part 4 - Add CacheIR optimization for GetIterator with null/undefined. r=jonco
Blocks: 1730863
Regressions: 1731540
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: