Description
Hello! I am currently working with sqlcipher 4.7.2 community edition
Currently room in android obtains sql connection in blocking way as seen here:
override fun query(query: String): Cursor =
session.useReaderBlocking { connection ->
connection.usePrepared(query) { stmt -> stmt.toCursor() }
}
in library only one connection can be created at the same time due to global mLock:
private SQLiteConnection waitForConnection(String sql, int connectionFlags,
CancellationSignal cancellationSignal) {
final boolean wantPrimaryConnection =
(connectionFlags & CONNECTION_FLAG_PRIMARY_CONNECTION_AFFINITY) != 0;
final ConnectionWaiter waiter;
final int nonce;
synchronized (mLock) {
That leads to whole default ArchTaskExecutor thread pool (that consists of 4 threads - used in room by default) being fully locked for 1+ second when first operations are executed
That is not good because in android it is usually a good practice to use coroutines that are not blocking. It also blocks default arch thread pool that is used by work manager workers, non-security room databases and etc
So the question is - is it possible to get rid of these locks or maybe speed up the connection creation somehow?
The other problem with this approach is that i can't use existing connections while another connection is created because releaseConnection locks the same lock as acquireConnection. Maybe it could be possible to execute queries/transactions on existing connection while creating one connection?