Replies: 2 comments 3 replies
-
Just as an update -- I've found an alternative approach that allows full incremental view maintenance of any sql query. The only drawback is it requires pre-compiling the queries ahead of time so the queries which need to be "live" have to be known ahead of time. Bind params are still supported allowed, however. We could get around compilation by creating a byte code interpreter (similar to how SQLite compiles and runs prepared statements) but that'll take a long while 😅 |
Beta Was this translation helpful? Give feedback.
-
I've been doing quite a bit of testing with Materialite and a fully in-memory SQLite DB. Fully in-memory SQLite given that is the absolute fastest setup for SQLite in the browser. The findings so far have been interesting in that Materialite dominates SQLite by an order of magnitude even for queries that can't be incrementally maintained. My hunch is that the cost of going from JS -> WASM is just incredibly high. + the extra work of going from raw string -> parsed string -> sql query plan when fresh queries are created. Materialite is also nice in that it doesn't matter if the developer does dumb things like returning 100,000 rows. Its still fast. the "dev doing dumb things" example:Materialite - Updating an issue in a list of 100,000 issuesdiff.movIn-Memory SQLite - Updating an issue in a list of 100,000 issueslivestore100k.movAnd an example of JS -> WASM cost just being incredibly high. Both Materialite and SQLite should be doing the exact same amount of work on query change since creating a brand new query has no incremental starting point. Non-Incremental QueriersMaterialite - new queries, no incrementalismfilter-mat.movSQLite - new queries, y so slow?filter-livesetore.mov |
Beta Was this translation helpful? Give feedback.
-
A follow up to: expo/expo#23728 (comment)
Update Hook
The
sqlite_update_hook
has a number of problems:WITHOUT ROWID
tablesWe can work around most of these:
commit
callbackwithout rowid
tables. Unless @groue knows some magic to deal with this.Fine Grained Observation
Given we have ways to make do with the update_hook, that brings us to "fine grained" reactivity.
The SQLite bindings I currently provide to React re-run a query if/when any table that the query used changes. This is regardless of what columns the query happened to use. This works pretty well until there are > 50 live queries.
@groue was gracious enough to spend some time answering questions about how GRDB handles observability and it looks like we can do better. We can:
The high level about how GRDB accomplishes this --
pre-update
hook -- https://sqlite.org/c3ref/preupdate_count.html. This callback tells us the values that individual columns will be set to on a write. To support this in a transactional manner, we'd need to pair this hook with thecommit
androllback
hooks such that we only update query results in-place after commit.@groue also brought up some points I hadn't considered when thinking through other reactive query approaches.
The GRDB approach seems to avoid these pitfalls.
For the reactive components of Vulcan I think following the same path as GRDB, maybe even porting their implementation of observability to Rust so we can compile to WASM for use in the browser, is the right medium term path.
Beta Was this translation helpful? Give feedback.
All reactions