Repository navigation
Stop making the synchronous relays async imports - #375
Merged
rhashimoto merged 1 commit intoOct 5, 2026
Merged
Conversation
src/asyncify_imports.json listed every relay twice, sync and _async, and both builds were passed that list. Emscripten already treats the methods marked __async as async imports, so the list only added the synchronous relays. On the JSPI build that wraps them in WebAssembly.Suspending, which Firefox charges almost as much as a real suspension on every call. dist rebuilt with emsdk 3.1.61; wa-sqlite.mjs/.wasm and wa-sqlite-jspi.wasm are unchanged.
Owner
|
Thanks for the PR! The performance boost on Firefox is great, but doing that while simplifying the build is really great. LGTM. |
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.
What happens
src/asyncify_imports.jsonlists every relay twice,ippandipp_asyncand so on, and the Makefile passes it asASYNCIFY_IMPORTSto both the Asyncify and the JSPI builds. Emscripten already makes every library method marked__asyncan async import (emsdk 3.1.61,tools/link.py:settings.ASYNCIFY_IMPORTS += ['*.' + x for x in js_info['asyncFuncs']]), andlibadapters.jsmarks exactly the_asyncrelays. So what the list adds is the synchronous relays.On the JSPI build, the glue wraps each of those in
WebAssembly.Suspendingtoo. When the function returns a plain value, Chromium charges little for the wrapper and Firefox almost as much as a real suspension. In a loop calling one empty import from a dedicated worker, a wrapper whose function returns at once costs 2.2-2.4 µs per call on Firefox 153 and 0.055-0.06 µs on Chromium 151; a plain import, 0.004 µs on both; a real suspension on Firefox, 2.7-3.0 µs. Every synchronous VFS method, authorizer, user function and hook pays it on every call. For example, an application that sets an authorizer and runs the JSPI build on Firefox spends most of each prepare crossing these wrappers.The change
The list goes, and
ASYNCIFY_IMPORTSwith it. The_asyncrelays stay async imports through__async, and the synchronous ones become plain imports.distis rebuilt with emsdk 3.1.61:wa-sqlite.mjs,wa-sqlite.wasmandwa-sqlite-jspi.wasmare unchanged, byte for byte;wa-sqlite-jspi.mjsandwa-sqlite-async.mjs, the import pattern no longer names the synchronous relays;wa-sqlite-async.wasmis 1104 bytes smaller, since Asyncify no longer instruments around them.A rebuild of
masterwith the same image reproduces the checked-indistexactly.Measured
µs per call, Playwright 1.62.1 (Chromium 151, Firefox 153), a dedicated worker, median of 5 pages, each the median of 5 rounds, the two builds alternated:
INSERT,MemoryVFSSELECTwith an authorizer setINSERT,MemoryAsyncVFSINSERT,MemoryVFSINSERT,MemoryAsyncVFSMemoryAsyncVFSgains too because only its open, close, read, write, size, delete and access methods are async; locking, syncing and file controls are the synchronous methods it inherits. The Asyncify build does not move on either engine.Test
No test changes: the change is in what the glue wraps, and the suite already runs every build. The whole suite passes on Chromium with
web-test-runner.config.mjs: 6488 passed, 0 failed, before and after. On Firefox (Playwright), file by file, the results are the same before and after; the only failures are the threevfs_read_freshnesstests onOPFSWriteAheadVFS, which needreadwrite-unsafe, andsql.test.jswas run without itsOPFSWriteAheadVFSconfiguration, whosesql_0005hangs the harness there (#373).Checklist
non-exclusive, royalty-free, irrevocable copyright license to reproduce, prepare
derivative works of, publicly display, sublicense, and distribute this
Contribution and such derivative works.
Contribution contains no content requiring a license from any third party.