web-platform-tests / interop

web-platform-tests Interop project
https://wpt.fyi/interop
308 stars 28 forks source link

JSPI (JavaScript Promise Integration) for WASM #766

Open fgmccabe opened 2 weeks ago

fgmccabe commented 2 weeks ago

Description

In order to support responsive applications written using WebAssembly it is necessary to provide functionality that allows WebAssembly programs to be suspended and resumed.The primary initial use case is to allow WebAssembly programs whose source relies on synchronous APIs to use asynchronous APIs that are increasingly common on the Web platform.The Promise integration proposal allows this to be done without changing the WebAssembly specification itself and without allowing JavaScript programs to be suspended (other than via existing async mechanisms).The feature is usable with any Promise-based JS or WebIDL API, but is especially useful for those targeted at high-performance applications, e.g. WebGPU. Interop 2024 proposal

In order to support responsive applications written using WebAssembly it is necessary to provide functionality that allows WebAssembly programs to be suspended and resumed.

The primary initial use case is to allow WebAssembly programs whose source relies on synchronous APIs to use asynchronous APIs that are increasingly common on the Web platform.

The Promise integration proposal allows this to be done without changing the WebAssembly specification itself and without allowing JavaScript programs to be suspended (other than via existing async mechanisms).

The feature is usable with any Promise-based JS or WebIDL API, but is especially useful for those targeted at high-performance applications, e.g. WebGPU.

Interop 2024 proposal

Specification

WebAssembly Phase 3 - https://github.com/WebAssembly/js-promise-integration

Additional Signals

Standards Positions

Mozilla - Positive https://github.com/mozilla/standards-positions/issues/944 WebKit - No information

Browser Bugs

Chromium Gecko

Tests

There is an active CL (https://chromium-review.googlesource.com/c/chromium/src/+/4908168) that will add JSPI tests to chromium and (by export) to wpt.fyi

Workarounds

The main work around is to use the binaryen ASYNCIFY feature. However, this can double the WebAssembly code size and cause a substantial reduction in performance (due to how ASYNCIFY works, the amount of code increase and performance cost varies depending on the complexity of the original source).

fgmccabe commented 1 day ago

As of https://chromium-review.googlesource.com/c/chromium/src/+/5922662, WPT tests for JSPI are in Chrome.