Skip to content

Why are there synchronous and asynchronous builds? #7

Closed
@rhashimoto

Description

@rhashimoto

WebAssembly currently doesn't have native support for coroutines or continuations. That makes it difficult to connect SQLite with browser resources that are inherently asynchronous, like IndexedDB.

Asyncify is a clever workaround for that restriction. It postprocesses the .wasm file and adds some library support to effectively suspend some WebAssembly calls, run some asynchronous Javascript, and resume executing the WebAssembly. That can be used to bridge C's customarily blocking i/o, which SQLite uses, and the browser's asynchronous APIs (though not the only way).

Asyncify is amazing and awesome, but it isn't free. It makes the WebAssembly substantially larger and slower, particularly with SQLite which is something of a worst case. Developers can decide whether the costs are acceptable for their application, but the asynchronous build should only be used if it is actually needed.

JavaScript Promise Integration (aka JSPI or stack switching) is a replacement for Asyncify approaching stable release in Chrome and Firefox. JSPI builds have been added to dist/, and are only slightly larger (~1%) than synchronous builds. Benchmarks on pre-release browsers show performance roughly equivalent to Asyncify.

Metadata

Metadata

Assignees

No one assigned

    Labels

    faqFrequently asked question

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions