Open Bug 2090089 Opened 22 days ago Updated 13 hours ago

Consider polymorphic transpilation

Categories

(Core :: JavaScript Engine: JIT, enhancement, P1)

enhancement

Tracking

()

Size Estimate M

People

(Reporter: iain, Unassigned)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [js-perf-next])

Attachments

(1 file)

In WarpOracle, IC chains with more than one active stub are not transpiled, causing us to generate an Ion IC. This makes us somewhat bad at small-N polymorphism: if there are more than 6 different stubs, we will transition to megamorphic mode and get a transpiled megamorphic IC, but 2-6 stubs fall in the gap.

The ML benchmark in JS3 is effectively bimorphic: it feeds two different implementations through the same code. The most recent JS3 foofrix batch contains many patches attempting to fix this, using an assortment of ad-hoc mechanisms.

The principled approach is to transpile more than one IC. When an IC chain is polymorphic, we can a) snapshot the CacheIR for all active stubs, b) generate MIR for each of them, replacing (eg) GuardShape with CompareShape + Test, so that a failed guard moves to the next option instead of bailing, c) optimize shared CacheIR prefixes/suffixes to eliminate repeated code, and d) decide whether to bail out or use an IC after all existing transpiled stubs fail. (We might also want to reduce the maximum stub count from 6 to 4 or so.)

This would be a big win for ML. There is some anecdotal evidence that it would also be useful in some of the SP4 candidate tests (we're using the generic call trampoline for fn.apply({}, arguments)), but we haven't fully verified that it would be fixed by polymorphic transpilation.

Some ML cases might also want polymorphic inlining, but we can burn that bridge when we get to it.

js-perf-next: Prototype this and see what it helps.

Here's a version of this https://github.com/jrmuizel/firefox/commit/fe68e87b921c067ecc76cef1f9a70499574c4400 that Claude found when looking at a Facebook benchmark. The targeted code seems to come from https://github.com/meta/hyperion which has hot functions that look like:

function() {
  var l;
  return l = e.implementation.apply(this, arguments),
    e.onAfterCallObserver.call.call(this, l),
    l
}

and

function() {
  return a.dispatcherFunc.apply(this, arguments)
}

That fix improved the benchmark by 10%

Size Estimate: --- → M

This problem shows up in chat-stream-octane as well:

Here's an example:

function refreshBlockForContext(block) {
  const verified = block.$$ctxDepsEpoch === EPOCH_CELL.value;
  if (!verified && ctxDirectChanged(block)) {
    if (typeof __OCTANE_PROFILE_ENABLED__ !== "undefined" && __OCTANE_PROFILE_ENABLED__)
      __profileSchedule(block, "context");
    renderBlock(block);
  } else if (block.body?.__memo === true || block.$$implicitBail === true) {
    if (!verified) {
      if (ctxDepsChanged(block)) refreshContextConsumers(block);
      else block.$$ctxDepsEpoch = EPOCH_CELL.value;
    }
  } else {
    if (!verified) block.$$ctxDepsEpoch = EPOCH_CELL.value;
    refreshContextConsumers(block);
  }
}

I prototyped a version of of polymorphic transpilation a few months ago and can try that on this micro-benchmark.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: