Skip to content

No FastPath for new Array(constant) #1271

@kunalspathak

Description

@kunalspathak

Today we don't generate fast path for below case.

var x = new Array(5); // argument should be constant between 0 and 8 inclusive.

That is because in lowerer , we fetch the wrong source of instruction. I tried fixing it by extracting the right argument and based on that emit fast path. For below test case I saw 10% win.

var start = new Date().getTime();
function test() {
  var arr = [];
  for (var j = 0; j < 100; j++) {
    arr.push(new Array(5));
  }
  return arr;
}

for (var i = 0; i < 1000000; i++) {
  test();
}
var end = new Date().getTime();
var time = end - start;
print(time);

However, I later realized that Array ctor can take multiple parameters that are array elements and we need to emit code to initialize those elements in fast path. If we should/do not want to emit fast path if parameters are array elements (although less than or equal to 8), then my solution should work and I can submit the PR for this.

This was never caught because the only other code path that creates this fast path is NewScObjArrayNoArg.

I was also curious why we decided to emit fast path only for array length up to 8 and not beyond. On scanning through benchmarks, I noticed that this would improve Sunspider but other benchmarks like Octane, Jetstream, etc. won't be improved because they create Array from ctor of length around 1024 or greater.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions