Skip to content

Support OPFSWriteAheadVFS, concurrent reads#930

Open
simolus3 wants to merge 4 commits intomainfrom
opfs-concurrent-reads
Open

Support OPFSWriteAheadVFS, concurrent reads#930
simolus3 wants to merge 4 commits intomainfrom
opfs-concurrent-reads

Conversation

@simolus3
Copy link
Copy Markdown
Contributor

This adds an option to use the new OPFSWriteAheadVFS VFS under WASQLiteVFS.

Unlike the existing VFS implementations, this one supports concurrent reads through a write-ahead log. To make use of that in the PowerSync SDK, we use a simple concurrency setup:

  1. When the VFS is enabled, we spawn two dedicated workers instead of one. On the second worker, we open the database in read-only mode.
  2. In AsyncConnectionPool, we may use the read worker for read locks if available.

This is probably not an optimal setup, but since it's only used as a new feature we can tune this after an initial release. Some obvious concerns:

  • Should we support more than one read connection? We could wrap multiple connections into a pool using our Semaphore utility, but I'm a bit worried about resource usage. Especially if users open many tabs at once, we probably don't want each tab to keep multiple read workers open (they listen to a broadcast channel to catch up with the WAL even when idle). We could investigate support for a read pool resizing based on how many queries a tab runs.
  • Selecting a connection: Our other connection pools delegate all reads to dedicated read connections. Since we only have a single read connection here, it makes sense to keep using the write connection for reads too (so that we can speed up read-heavy workloads). In this PR, I'm using whatever connection has fewer in-flight requests. That's a pretty terrible metric, a long-running write transaction would block some reads scheduled for the write connection in this case. Better concurrency control would definitely help here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: b56020d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@powersync/web Minor
@powersync/diagnostics-app Patch

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

@simolus3 simolus3 force-pushed the opfs-concurrent-reads branch from 9f83de6 to 2c3f243 Compare April 14, 2026 14:36
@simolus3 simolus3 marked this pull request as ready for review April 14, 2026 14:57
@simolus3 simolus3 changed the title WIP: Support OPFSWriteAheadVFS, concurrent reads Support OPFSWriteAheadVFS, concurrent reads Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant