feat(sqlite): Replace deadpool-sqlite by our own implementation
#5841
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,