Description
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:
- WooCommerce crash #967
- Can’t place orders in Woo when HPOS is enabled #731
- PHP-WASM: improve phar support (Asyncify error – null function or function signature mismatch) #1241
- Curl extension for the Node.js build of PHP.wasm #1273
- Add PHP iterator and yield support #1181
- Fix shutdown errors #1104
- PHP: Add zif_array_filter to Asyncify list #397
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:
- JSPI: Enable the origin trial on Chrome #1346
- 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)
- Deploy both bundles to playground.wordpress.net
- Ship the JSPI version to Chrome users, ship the Asyncify versions to everyone else
- 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 atchrome://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