-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
poc: Configurable Web VFS #418
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 77543e3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Unsolicited drive-by comment:
OPFS itself doesn't require the COOP/COEP headers and associated restrictions. Some SQLite VFS implementations use SharedArrayBuffer to provide a synchronous interface for SQLite, and that is what requires COOP/COEP, not OPFS. However, no example VFS in wa-sqlite uses SharedArrayBuffer. If you are using any VFS from the wa-sqlite project then COOP/COEP headers are unnecessary. |
Thank you for the tip/catch, @rhashimoto! I copied this from our Dart docs without fully verifying it yet, so this is really helpful. I'll review the relevant sections and update them as needed. It's a personal honor to have you comment on this. |
Overview
This POC adds support for configuring different SQLite virtual filesystems on Web.
WA-SQLite's
IDBBatchAtomicVFS
is still used as the default VFS.Synchronous Origin Private FileSystem (OPFS) VFS options are added. See WA-SQLite README for more details.
Notes
Configuration
OPFS can be configured with a
WASQLiteOpenFactory
. These options could be added to the default web constructor.HTTP Requirements
The use of OPFS requires a secure context and additional HTTP headers when serving a web application. These are already documented for the Dart SDK.
For Vite these headers can be configured in the Vite config file:
vite_config.mts
Multiple Tab Support
The OPFS VFS currently only works in dedicated web workers. The current multiple tab support implementation has been updated in order to cater for this. For IndexDB we still use a single
SharedWorker
which manages a single SQLite connection between tabs. For OPFS each tab uses its own dedicatedWorker
which has its own SQLite connection. Table update notifications are shared between tabs via aBroadcastChannel
. Exclusive locks between tab connections are maintained through Navigator locks as usual.The initialisation for Web
DBAdapter
s has been streamlined and extended in order to support OPFS. The abstractions and sharing of implementation is managed by new internal APIs and classes.Safari Multiple Tab Support
The new code structure seemed to fix the long outstanding Safari multiple tab support issues when using
pnpm serve
but doing a build and usingpnpm preview
still shows the same problem.However, using OPFSCoopSyncVFS now provides multiple tab support for both Safari and Safari iOS.
This is not yet enabled by default but can be enabled with an appropriate flag.
OPFS VFS and Multiple tabs
The
AccessHandlePoolVFS
does not seem to work well when more than 1 dedicated worker accesses the filesystem.OPFSCoopSyncVFS
works with multiple tabs.Performance
OPFS (with AccessHandlePoolVFS) has been observed to be significantly faster than the IndexDB filesystem. The time to sync 23_000 rows was compared between IndexDB and OPFS
IndexDB
OPFS
TODOS