Skip to content

Cache prepared statements in web workers#1020

Draft
simolus3 wants to merge 3 commits into
v2from
web-statement-cache
Draft

Cache prepared statements in web workers#1020
simolus3 wants to merge 3 commits into
v2from
web-statement-cache

Conversation

@simolus3

@simolus3 simolus3 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

This adds the preparedStatementsCache option to web databases, which controls the size of a cache for prepared statements. When set to a value greater than zero, workers store an LRU cache with the configured maximum capacity for statements.

Caching statements can improve performance by not having to prepare common queries every time they run. In particular, this can have a positive effect for watched queries and internal statements like powersync_control invocations. The statement cache is currently disabled by default.

Ideally, we should also do this in the Node.js SDK. However, we also shouldn't cache EXPLAIN statements as they are only evaluated on the first prepare and thus don't reflect schema changes. Neither better-sqlite3 nor node:sqlite3 exposes a way for us to know whether a statement is an EXPLAIN, so we can't safely cache those.

AI use: Manually implemented, then revised with Claude Code.

@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4767ef2

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

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