Hello! I stumbled upon <this tweet> the other day,...
# apollo-kotlin
e
Hello! I stumbled upon this tweet the other day, which made me wonder, does apollo-normalized-cache-sqlite use Write-Ahead Logging? Doing a quick Find in files, I couldn't find any reference to WAL in the project. Would enabling it speed up the SQLite cache maybe?
s
I tried re-implementing some of the SQL normalized cache factory a while back, looking for for performance improvements. Not sure whether WAL is on by default, but forcing it on with my own implementation I didn’t see any improvement (for our use case at least). Likewise for ‘synchronous’ pragma, and when experimenting with the ‘vacuum’ command or ‘optimize’ pragma. That’s not to say it might not be worth benchmarking now though!
b
Hi! Didn't know about WAL, interesting stuff! 👀 That being said it's worth mentioning that currently read/writes in Apollo Kotlin go through a lock (Java's ReentrantReadWriteLock on the JVM / AtomicFu's ReentrantLock on Native (read and write are not distinguished))
a
if using the androidx db library, itll turn the WAL mode by default on for you
Copy code
JournalMode resolve(Context context) {
            if (this != AUTOMATIC) {
                return this;
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                ActivityManager manager = (ActivityManager)
                        context.getSystemService(Context.ACTIVITY_SERVICE);
                if (manager != null && !isLowRamDevice(manager)) {
                    return WRITE_AHEAD_LOGGING;
                }
            }
            return TRUNCATE;
        }
since apollo uses it internally then itll turn it on with this logic.
s
Apollo doesn't use room internally, since room isn't multiplatform. It uses SQLDelight which doesn't have any such internal logic afaik. Or am I completely misunderstanding what you're saying here 😅
a
its not room ,its androidx
Copy code
factory: SupportSQLiteOpenHelper.Factory = FrameworkSQLiteOpenHelperFactory(),
from
SqlNormalizedCacheFactory
which
sqldelight
uses under the hood
looking at sqldelights android driver i do not see any changes to the default
journalMode
which I mentioed above
e
Cool, so if I understood it correctly, concurrent reads should work already, no? 😄