Allow caching prepared statements#150
Conversation
79c8dfa to
5cfd4bd
Compare
5cfd4bd to
ff6a17d
Compare
rkistner
left a comment
There was a problem hiding this comment.
Adding a configurable cache seems like a good idea.
I think we should explicitly note the potential caveats of the cache in the docs. One that I've seen in the past is that an open statements can block dropping a table or index, such as in this example.
I also noticed the PR description mentions a default cache size of 10, but the code mentions 0 - I assume the latter is the correct default?
It looks like that comment is outdated from powersync-ja/powersync-sqlite-core@c023c89 since we no longer have a prepared statement there, but it's still a good point in general. We call
Yes, I initially added a cache by default but considering that this is a patch release I think it's better to leave it disabled by default. I have updated the PR description. |
This adds the
preparedStatementCacheSizeoption, which is supported both for native (sqlite3_connection_pool) and web (sqlite3_web) databases. For web databases, the statement cache is implemented in Dart and managed by the web worker. For native databases, the cache is implemented in Rust and shared between isolates.With a cache size of 10 statements, this provides a modest performance improvement compared to not caching any prepared statements:
To be able to release this in a patch release without much risk, this does not enable statement caching by default.