feat(sqlite): Replace deadpool-sqlite by our own implementation#5841
Merged
Hywan merged 3 commits intomatrix-org:mainfrom Nov 11, 2025
Merged
feat(sqlite): Replace deadpool-sqlite by our own implementation#5841Hywan merged 3 commits intomatrix-org:mainfrom
deadpool-sqlite by our own implementation#5841Hywan merged 3 commits intomatrix-org:mainfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5841 +/- ##
=======================================
Coverage 88.61% 88.61%
=======================================
Files 361 362 +1
Lines 102269 102292 +23
Branches 102269 102292 +23
=======================================
+ Hits 90627 90648 +21
- Misses 7420 7422 +2
Partials 4222 4222 ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #5841 will not alter performanceComparing Summary
|
5c889a8 to
0a3a594
Compare
This patch replaces `deadpool-sqlite` by our own implementation in `crate::connection`. It still uses `deadpool` but the object manager has a different implementation.
This patch explains why we create our own implementation of `deadpool` for `rusqlite`.
This patch removes the `connection::Config` type. It was “inspired” from `deadpool_sqlite`, but we can clearly remove it by using our own `SqliteStoreConfig` type. It simplifies the way we open a database.
0a3a594 to
eaec1db
Compare
jmartinesp
approved these changes
Nov 11, 2025
Contributor
jmartinesp
left a comment
There was a problem hiding this comment.
I've been using it for 4 days now with no issues and outstanding performance, so it definitely LGTM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Initially, we were using
deadpool-sqlite, that is also usingrusqliteas the SQLite interface. However, in the implementation ofdeadpool::managed::Manager, when recycling an object (i.e. an SQLite connection), an SQL query is run to detect whether the connection is still alive. It creates performance issues:deadpool_runtime::spawn_blockingis used (viadeadpool_sync::SyncWrapper::interact), which includes using a blocking thread (they are limited), acquiring a lock etc. All this has more performance cost.Measures have shown it is a performance bottleneck for us, especially on Android. Why specifically on Android and not other systems? This is still unclear at the time of writing (2025-11-11), despite having spent several days digging and trying to find an answer to this question (kudos to @jmartinesp who didn't count its hours on this…).
We have tried to use another approach to test the aliveness of the connections without running queries. It has involved patching
rusqliteto add more bindings to SQLite, and patchingdeadpoolitself, but without any successful results.Finally, we have started questioning the reason of this test: why testing whether the connection was still alive? After all, there is no reason a connection should die in our case:
Consequently, we have created a new implementation of
deadpoolforrusqlitethat doesn't test the aliveness of the connections when recycled. We assume they are all alive.This implementation is, at the time of writing (2025-11-11):
deadpool-sqlite, removing the lock and thread contention entirely,