alexstyl / contactstore

A modern, strongly-typed contacts API for Android.
https://alexstyl.github.io/contactstore
Apache License 2.0
440 stars 15 forks source link

Investigation: How much RAM does Contact Store when fetching a lot of contacts? #37

Closed alexstyl closed 2 years ago

alexstyl commented 2 years ago

Use the profiler that comes with Android Studio to investigate how much memory is required by Contact Store when fetching contacts.

More specifically, I would like to understand how much memory is required when doing a query for all contacts of the device. Testing with 1000 contacts sould be enough for testing.

You can use an app such as this to populate the device with multiple contacts.

More info

Someone reported a crash from production from a low end device. The crash seems to be related to Cursor allocation.

crash

The user also mentioned that their app crashes with a similar crash from Room:

Fatal Exception: android.database.CursorWindowAllocationException
Cursor window allocation of 2048 kb failed.

android.database.CursorWindow.<init> (http://CursorWindow.java:108)
android.database.sqlite.SQLiteCursor.getCount (http://SQLiteCursor.java:132)
-LINE REMOVED-
http://androidx.room.CoroutinesRoom$Companion$createFlow$1$1$1.invokeSuspend (http://CoroutinesRoom.java:2)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (http://BaseContinuationImpl.java:4)
http://kotlinx.coroutines.DispatchedTask.run (http://DispatchedTask.java:86)
java.util.concurrent.ThreadPoolExecutor.runWorker (http://ThreadPoolExecutor.java:1162)
http://java.lang.Thread.run (http://Thread.java:764)

Both crashes seem to be related to memory allocation. I can think of ways of reducing the memory required by Contact Store, but we need to understand the memory required first.

Device Specs

https://www.gsmarena.com/tecno_pouvoir_3-9866.php

wfR8ooiu jpg large

alexstyl commented 2 years ago

Closing this as no longer relevant.

Querying all contacts without any Columns should be light in memory. Also 99% of the times you won't need to keep any contacts in memory, as the ContactPredicate allow you to find any contact you need optimally (i.e. for matching phone numbers to contacts)