Replies: 2 comments 1 reply
-
|
We don't rely on Dart-defined SQL functions or custom hooks, so the proposed approach works well for our use case. We're using sqlite_async in a book reader app with a fairly heavy read workload — 20+ books, 50K+ paragraphs, and ~2M words stored, alongside user/sync data, with FTS5 for full-text search. The performance improvements from the new isolate model would actually be very welcome given our query volume. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Would this impact the drift ORM package support? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR: We're considering options to make this package faster on native platforms, but that requires getting rid of Dart-defined SQL functions. Please complain if you're currently using those.
On native platforms, sqlite_async works by spawning a pool of isolates (one writer and multiple readers) and then using a custom RPC-style protocol to exchange messages implementing asynchronous access to SQLite.
Counterintuitively, the following approach is actually more performant:
Isolates use green threads in recent Dart versions, so spawning them is cheap. Also,
Isolate.runexploits a clever optimization: Because the temporary isolate exits when its result is returned, the result object can be moved instead of being cloned through send ports! Especially for result sets with lots of small objects, this is significantly faster.The sqlite3_connection_pool package implements this approach. It also stores the connection pointers in Rust, which allows using NativeFinalizers to close connections on reloads. Also, Rust state is shared across isolates which means we can get rid of “isolate connection factory” tricks to share databases. Instead, connection pools are looked up by names, and shared even across multiple Flutter engines (e.g. UI app and background worker).
A very strong downside is that connections are used from multiple isolates (never concurrently, but still). This means we can’t install Dart callbacks on the SQLite connections, as those can only be called on the owning isolate (outside of this experimental feature). Without further workarounds, this prevents:
I believe the benefits of simplifying this package and making it more performant outweigh the lack of user-defined functions. However, we'd like to get input from users of this package as well. Are you currently relying on Dart-defined SQL functions? If so, please let us know!
Beta Was this translation helpful? Give feedback.
All reactions