Skip to content

Ship the JSPI kitchen-sink build to Chrome users #134

Closed
@adamziel

Description

@adamziel

Description

We use Asyncify to call asynchronous JavaScript functions from synchronous WebAssembly code.

However, Asyncify forces us to maintain a large list of all the C functions that can be at the call stack at the time of making an asynchronous call must be listed during the build. When we miss even one, that code path triggers a fatal crash ("unreachable" WASM instruction executed). People report those crashes rather often.

JSPI (proposal) is the new API that doesn't require maintaining that list and produces a smaller and faster binary.

Let's explore migrating to JSPI to solve these issues and more:

Next steps

We have a PR adding JSPI Support. It works in Node.js v22 and Chrome – both require a feature flag or applying to an origin trial.

I don't expect stable JSPI support in all major runtimes (Chrome, Firefox, Safari, mobile browsers, last 3 Node versions) for the next year, two, or even three. I'm happy to be wrong here, but I didn't see any proof of imminent rollout.

Here's what we could do:

  1. JSPI: Enable the origin trial on Chrome #1346
  2. Adjust the PR to build both the Asyncify and JSPI versions of the kitchen sink bundle (but not of the light bundle to save on the build time)
  3. Deploy both bundles to playground.wordpress.net
  4. Ship the JSPI version to Chrome users, ship the Asyncify versions to everyone else
  5. Keep the Node.js on Asyncify for the time being

This should get us:

  • Less people experiencing Asyncify crashes
  • An easy way to upgrade more users to JSPI as other browsers catch up

Runtime support as of April 29th, 2024

JSPI is supported on:

  • ✅ Google Chrome with #enable-experimental-webassembly-jspi enabled at chrome://flags, or with sites where the JSPI origin trial is enabled.
  • ✅ Node.js v22+ with --experimental-wasm-stack-switching feature flag.
  • Firefox nightly
  • ❌ Safari, older browsers
  • ❌ Bun, Node.js <= 21
  • ❔ I'm Not sure about Chrome-based browsers

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