Closed Bug 1730699 Opened 3 months ago Closed 3 months ago

Optimize for-in with null/undefined better


(Core :: JavaScript Engine, task, P3)




94 Branch
Tracking Status
firefox94 --- fixed


(Reporter: jandem, Assigned: jandem)


(Blocks 2 open bugs)



(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);

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.

Blocks: sm-jits
Pushed by
part 1 - Treat empty iterators for null/undefined as immutable and unlinked. r=jonco
part 2 - Cache empty iterator on the global. r=jonco
part 3 - Clean up CacheIR code for GetIterator a bit. r=jonco
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.