Skip to content

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented Jun 30, 2025

Overview

Certain environments have trouble loading PowerSync due to it requiring a SQLite implementation which supports loading our Rust core extension. One of these environments is Expo Go which is a prebuilt app container for Expo apps.

The new dev package uses a pure JS implementation of SQLite via SQL.js which has been forked. SQLite and our Rust core extension are compiled to JavaScript via Emscripen there. This pure JS payload can be used in environments such as Expo Go.

Outstanding work

  • There were some weird issues with using SQL.js update hooks. I've(Steven) added our own implementation as a workaround. As an alpha release this should suffice.
  • SQL.js operates in memory. We can persist the entire DB to disk on commit though. This has not yet been implemented for RN. Added Expo persister in the adapter-sql-js adapter's README.md
  • This currently builds SQL.js in the monorepo. This requires toolchains which we should not expect all users of the monorepo to have present. We could fallback to prebuilt assets in such cases. This build was moved out to the SQL.js fork.
  • Topology: The sql js fork is in a standalone repo, and we wrap it in our adapter-sql-js package. The adapter-sql-js package is no longer re-exported by react-native as that affected the bundle size for production build.
  • Document how and when to use this package. Likely that we want developers to use this for development and promote themselves to prod adapters for their respective platform.

Demo

ExpoGo2.mp4

Benchmarks

Tested 1000 separate list insertions, PowerSync not connected. Haven't been able to understand why the Expo file persister version is faster than the in-memory persister.
image

Copy link

changeset-bot bot commented Jun 30, 2025

🦋 Changeset detected

Latest commit: 19c70c7

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

This PR includes changesets to release 8 packages
Name Type
@powersync/adapter-sql-js Patch
@powersync/common Minor
@powersync/node Patch
@powersync/op-sqlite Patch
@powersync/react-native Patch
@powersync/tanstack-react-query Patch
@powersync/web Patch
@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

@Chriztiaan Chriztiaan changed the title [POC] SQL.js feat: @powersync/dev-adapter added to support SQL.js Jul 14, 2025
@Chriztiaan Chriztiaan changed the title feat: @powersync/dev-adapter added to support SQL.js feat: @powersync/dev added to support SQL.js Jul 15, 2025
@Chriztiaan Chriztiaan marked this pull request as ready for review July 24, 2025 12:15
@Chriztiaan Chriztiaan requested review from rkistner and simolus3 July 24, 2025 12:18
Copy link
Contributor

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a really helpful addition for Expo Go users 👍

I've left some minor comments. One other thing that stands out is that we may want to make it clearer in the readme (or perhaps even by logging something when the database is opened) that this is intended for development only. In particular, I feel like we should warn about this being much slower than the "real" SDK, so that we don't get reports about general PowerSync performance coming from users only trying the SQL.js adapter because it's the easiest one to use.

simolus3
simolus3 previously approved these changes Jul 28, 2025
Copy link
Contributor

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

simolus3
simolus3 previously approved these changes Jul 28, 2025
@Chriztiaan Chriztiaan changed the title feat: @powersync/dev added to support SQL.js feat: @powersync/adapter-sql-js added to support SQL.js Jul 29, 2025
@Chriztiaan Chriztiaan merged commit a1abb15 into main Jul 30, 2025
10 checks passed
@Chriztiaan Chriztiaan deleted the poc-sqljs branch July 30, 2025 07:49
Comment on lines +98 to +100
this.writeScheduler = new ControlledExecutor(async (db: SQLJs.Database) => {
await this.options.persister.writeFile(db.export());
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the benchmarks, this is probably the cause for slowdown for the in-memory config: This is doing an export of the entire database, right before discarding it. Using a filesystem probably gives better performance because it effectively throttles the exports while waiting for the write, while "in-memory" could trigger an export for every write.

I'd recommend setting persister to null and bypassing this step for the default/in-memory config, instead of creating a no-op persister.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix in a follow up PR.

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.

5 participants