Repository navigation
ariadne_wasm: JSPI measured against Asyncify for browser guests (G2, last part) - #1272
Merged
Merged
Conversation
…last part) src/ariadne_wasm/bench/jspi_bench.mjs builds five C workloads as guests (jspi_guest.c), meters them, and runs them in headless Chrome four ways: plain, metered, metered then Asyncify (today's install) and metered under JSPI, unsliced and sliced. A host (jspi_host.cpp) built under Asyncify or JSPI, with no exceptions, JS exceptions or wasm exceptions, polls a guest from N frames down. Every variant's result and gas is checked against the others'. What it found (Chrome 157, sandipaws): - Asyncify more than doubles a metered guest (14.3 to 30.3 MiB for a 9.1 MiB C++ module) and runs call-heavy code at half speed or less. Under JSPI a guest runs at the metered speed. - A pause: Asyncify 0.5 us at the top of the stack and 3.7 us 48 frames down; JSPI about 1.0 us at any depth. - ariglx's stack at a slice is 34 frames, 13 of them through invoke_* (libcvc's JS exceptions). JSPI can't suspend JS frames, and a JSPI host built with JS exceptions doesn't run at all. So ariglx would wait for a JSPI guest through its own Asyncify: 11.4 us a slice, against 0.7 for an Asyncify guest. A JSPI host with wasm exceptions waits 0.6 us at any depth. So Asyncify stays the browser's way to pause a guest. A page on JSPI throughout would win everywhere, but needs every wasm package on wasm exceptions. That is open question 13 in the roadmap. docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md: §8.5's as-measured section, §5.3's third fallback, open question 13, and the G2 row (done).
transfix
force-pushed
the
feat/wasm-jspi-vs-asyncify
branch
from
November 15, 2026 21:20
5dffd1f to
8772230
Compare
transfix
enabled auto-merge (squash)
November 15, 2026 21:20
transfix
added a commit
that referenced
this pull request
Nov 16, 2026
Conflicts (includes in ariadne.h, ariadne.cpp and ariadne_runtime_test.cpp; three hunks of #1241's menubar tray in ariadne.cpp) keep both sides. #1241's code meets this branch's groups: - An action's context keeps master's scope (a quit application's actions stop) and is built by this branch's finish_context. - The notify verbs bind by kind with the backend's (install_backend_verbs is now install_host_verbs): host_proxied in an `any` group, as cvc::notify mirrors the feed into the app's notify.* subtree raw on the caller's thread. - What they capture (scope, source, a copy of mount_names) is taken on the host thread when a context is made (NotifyScope); a spawned child, made on the thread that pumps its group, binds from its parent's copy through its spawn context instead of reading mount_names there. - quit_app kills the application's actions on current_sched() (the document's group), not only on group 0 when this Runtime used it. - drain_begin runs builtin_event before the handler seam, through this branch's `m`. Tests: AriadneIsolatedDocs.TheNotifyVerbsRunOnTheFramesThread (the feed is written on the frame's thread while a worker pumps the program; a spawned child posts as its parent's scope) and AriadneIsolatedDocs.QuitKillsALoadedDocumentsActionsInItsGroup. STATE_EXEC_THREADED.md: the notify verbs' row, Quit among the kills that go to the group, and the spawned child's notify scope.
This was referenced Nov 16, 2026
transfix
added a commit
that referenced
this pull request
Nov 17, 2026
#1308) * docs: JSPI and wasm exceptions across the browser stack (JX1-JX4 plan) Joe decided on 2026-11-16 to move every wasm host from Asyncify to JSPI, and libcvc and every cvcpkg wasm package from JS exceptions and longjmp to wasm's own. That settles ARIADNE_SCRIPTING_HOSTS.md section 9, item 13. WASM_JSPI_EXCEPTIONS.md is the plan. It covers: - why (#1272's numbers); - a mixed-link table from emsdk 5.0.7, which shows the break runs both ways; - which archives in ariglx-web's closure use JS longjmp or JS exceptions; - the four phases: JX1 cvcpkg, JX2 libcvc, JX3 guests, JX4 the switch. Section 8.5 now gives the current browser support (Firefox 153 and Safari 27 have shipped JSPI). It also says there is no Asyncify fallback, since Asyncify and wasm exceptions don't compose. * docs: JX1 as built: EMCC_CFLAGS, the catalog scan's 13 recipes, and the PR open until JX4 JX1 started in cy-pca/cvcpkg (feat/wasm-exceptions): - The flag goes through EMCC_CFLAGS, which only emcc reads, not CFLAGS, since several recipes build native host tools beside it. - The pack gate reads wasm import sections itself and checks LTO bitcode's personality. - A scan of all 126 latest wasm and wasm-mt bundles on cvcpkg.org found 13 cvcpkg recipes with JS-exception or JS-longjmp objects, plus libcvc's own three. Only those 13 are bumped. - The cvcpkg PR stays open until JX4: on master, the flag would put bundles today's libcvc can't link onto prod.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
G2's last part (ARIADNE_SCRIPTING_HOSTS.md §8.5, §9 item 13): JSPI measured against Asyncify for WebAssembly guests in the browser. One commit on master, after #1245: a bench and the roadmap's write-up. No shipped code changes.
What it found
Asyncify stays the browser's way to pause a guest. JSPI would make guests smaller and faster, but today's
ariglxcan only wait for a JSPI guest through its own Asyncify, at about 11 µs a slice. A page on JSPI throughout would win everywhere, but it needs every wasm package on wasm exceptions. That is left open in §9, item 13.Measured in headless Chrome 157 on sandipaws. Chrome's processes ran at High priority on a busy box; each number is the median of 9 rounds, each round timing every variant once.
Size. Asyncify more than doubles a metered guest:
ari_wasm_meter.wasm, metered, grows from 0.4 to 1.0 MiB;ariadne_wasm_browser_test.wasm(9.1 MiB as built) grows from 14.3 MiB metered to 30.3 MiB (3.9 to 7.8 MiB gzipped).Asyncify took 594 s on that last one, and metering took 0.3 s. A JSPI guest is just the metered one.
Speed, unsliced, against the metered guest.
fib30.1 ms against 14.1,qsort1495 against 530, SHA-256 80 against 62, the interpreter 370 against 339, a loop 52 against 46.A pause.
The host's wait.
ariglx's stack at a slice. I probed the smoke'sguest.aripage: 34 frames are below the guest, and 13 of those calls go throughinvoke_*. That is Emscripten's JS exception handling, which libcvc builds with.A JSPI host built like that doesn't run at all. JSPI can't suspend a stack with JS frames on it. Under
-sJSPI, Emscripten also makes everyinvoke_*a suspending import, so nested calls fail with "SuspendError: trying to suspend JS frames" even when nothing waits.So
ariglxwould wait through its own Asyncify. A poll at 1,000-gas slices costs:ariglx)ariglx)So, per default slice (64,000 gas) in today's
ariglx: a JSPI guest pays about 11 µs to save Asyncify's cost to its code.fibandqsortthat cost is 36 and 41 µs, so JSPI wins.A page on JSPI throughout would win everywhere. The host's wait drops to 0.6 µs, the guests skip Asyncify, and the host's own Asyncify cost from W1 goes too: CPython at half speed, and 8% of the module. What it needs:
-fwasm-exceptionsacross libcvc and every wasm package. Rust's Emscripten target needs the same move to link into cvcdbg's wasm build.G3's WAMR needs the Asyncify build anyway.
The bench
src/ariadne_wasm/bench/. It isn't built by CMake or run in CI.jspi_guest.c: the five workloads.fib;qsort;jspi_host.cpp: the host. It recurses N frames, each holding an object with a destructor, then polls the guest. The driver builds it five ways: Asyncify or JSPI, with no exceptions, JS exceptions (-fexceptions, as libcvc) or wasm exceptions.jspi_bench.jsandjspi_bench.html: the page. Three sections: the workloads, the pause cost, and the hosts.browser_runtime.cppdrives one.ari.gasas aWebAssembly.Suspendingand its exports throughWebAssembly.promising.jspi_bench.mjs: the driver. It builds everything with emsdk's emcc and wasm-opt andari_wasm_meter, takingCVC_WASM_GUEST_FEATURESfromariadne_wasm.cmake. Then it serves the page cross-origin isolated and runs it in headless Chrome over CDP.--sizesalso transforms other modules for sizes.--high-priority(Windows) raises Chrome's processes.Checked
jspi_guest.candjspi_host.cpp: clean.node --checkon both scripts.ariglx's stack ran on ariglx-web: WebAssembly guests in the page (G2, third part) #1245'sariglx-webbuild. That page passed itsguest.aricase with the probe in it.Not covered
ariglx.