SQLite User Forum

Blog post about using WASM SQLite in the browser
Login

Blog post about using WASM SQLite in the browser

(1) By ddevienne on 2024-07-23 07:08:32 [link] [source]

FYI. From Notion:

How we sped up Notion in the browser with WASM SQLite

(2) By Stephan Beal (stephan) on 2024-07-23 08:19:05 in reply to 1 [link] [source]

From Notion:

We'll be meeting with them soon to discuss that experience and see what we can learn and improve upon from it.

(3) By Randy (randyl) on 2024-07-23 18:23:53 in reply to 1 [link] [source]

Thank you for posting that article! It was an interesting read. It links to one of my messages on this forum about corruption issues. A number of times I've searched the internet but couldn't find anyone else talking about this problem. It's reassuring to know other people struggled with this; I'll see if I can adapt their architectural solution for my code base.

(4) By Roy Hashimoto (rhashimoto) on 2024-07-23 20:07:13 in reply to 3 [link] [source]

Just a note about Notion's approach: as described it isn't quite the same as the referenced method on GitHub. The Notion post says:

To execute any SQLite query, the main thread of each tab sends that query to the SharedWorker, which redirects to the active tab’s dedicated Worker.

This has each query taking two message hops to the SQLite WASM Worker. The referenced method uses a shared or service worker to establish a MessageChannel directly between the client and the dedicated Worker, so each query takes a single hop which is more efficient for use cases where that matters.

FYI there are some other complications to watch out for when sharing a connection that Notion may be handling but are not detailed in their post. For example, if a client issues a write transaction and the dedicated Worker dies before the response comes back then the client won't know whether the transaction was successful or not. If the application requires a successful commit then ideally the transaction would be idempotent and can be unconditionally retried, but if not then some mechanism for determining success or failure must exist.

(5) By Randy (randyl) on 2024-07-23 22:29:00 in reply to 4 [link] [source]

Thank you for those notes.

(6) By Randy (randyl) on 2024-07-31 02:33:02 in reply to 2 [link] [source]

Just curious, have you met with Notion? Are there any takeaways you can share?

(7) By Stephan Beal (stephan) on 2024-07-31 11:36:52 in reply to 6 [source]

Just curious, have you met with Notion? Are there any takeaways you can share?

We can share that we've started work on a "bare-bones" WASM build, stripping out all but the very core-most functionality, the goal being to shrink sqlite3.wasm as far down as we can. Essentially, it removes everything for which there is an SQLITE_OMIT_... flag and does not (with very few exceptions) enable the optional SQLITE_ENABLE_... flags.

It hasn't reduced the size as much as hoped (from 854kb to 604kb uncompressed, roughly 30% reduction) but we still have some tweaking to try to get that smaller. It's not yet clear whether we will distribute such a blob along with other releases, but it will (once it's merged) be available for those who are able to build it from the canonical source tree.