chakra-core / ChakraCore

ChakraCore is an open source Javascript engine with a C API.
MIT License
9.1k stars 1.19k forks source link

JIT Generator (and Async func) loops #6990

Closed rhuanjl closed 4 months ago

rhuanjl commented 5 months ago

Jitting of generator and async functions is buggy and has some potential performance cliffs. As an alternative this PR enables Jitting of loops that don't contain await or yield.

e.g. In this examples if the profiler found them to be hot loop 2 and loop 4 would be jitted:

async function boo()
{
  while (something) {  //loop 1
    while (stuff) {  // loop 2
      // do sums
    }
    while (otherStuff) { //loop 3
      await x
    }
  }
  while (moreStuff) { //loop 4
    //do more sums
  }
}

Whilst jitting the whole function may in theory offer better performance it's not actually clear that it would in light of the overheads of yielding out of jitted code AND the problems yield brings to optimising jitted code.

This alternative is much simpler; hopefully far more stable AND should target the most optimisable parts of these functions.

ppenzin commented 5 months ago

I think it is a pretty good idea.

rhuanjl commented 5 months ago

I've moved all generator JIT test cases into a new folder and added additional test cases for testing loop body jit.

Note, with this PR we now have:

Default behaviour (no flag): do not Jit generator (or async functions) BUT do jit hot loops inside them that don't contain yield or await.

Flagged behaviour -JitEs6Generators: turns back on attempting to JIT the generator/async functions AND disables this loop body Jit, having both working together may be a distant goal BUT for now the function jit is going to be disabled; and their interaction has additional bugs vs just the function jit on its own.