Essentials
Essentials copied to clipboard
[Bug] Contacts -> GetAllAsync very poor performance on Android
Description
When trying to retrieve the full contact list in devices with over 1000 contacts the performance is not appropiate and we observe the ANR graphs in google play console skyrocket to 3-4%. The implementation is not the recommended it seems and many stackoverflow posts talk about this topic. Also found a blog talking about "the good, the bad and the ugly" in this topic which can maybe work to improve the Essentials Library
Steps to Reproduce
- Get a device or emulator with many contacts (preferably more than 1000 although more makes it more noticeable)
- Call GetAllAsync on Android on any View
Expected Behavior
Contacts load taking its time but not freeze the app.
Actual Behavior
Android show "Application XXX is not responding" prompt as if the main thread is locked.
Basic Information
- Version with issue: 1.7.1
- Last known good version: None
- IDE: VS for mac 8.10.22 (build 11)
- Platform Target Frameworks: -Android >= API 21 (5.0)
PS: Thank you very much for all the work put into this library, its awesome :)
When I implemented it I was thinking about it... If the user has a lot of contacts we will have perf. issues... I can see two solutions for this:
- Use
IAsyncEnumerable; - Create some kind of pagination. If I'm not wrong we can pause the Task execution.
This is the blogpost I read a few weeks ago about it: https://medium.com/swlh/the-good-the-bad-and-the-ugly-three-approaches-to-loading-contacts-in-your-android-application-c96eaf03ffaf
Im not sure if chaning the implementation is something viable but the post has some interesting approaches. Seems like not so long ago Google added Loader classes to deal with this kind of task.
Im sorry I cannot be more helpful about it
@cjrvdev thanks for the reference... Yeah, I don't know if the team wants to make the change here, since this repo is in code freeze mode. If the fix for this issue is something "simple" it can be merged here, but if we have to change the implementation I believe that we should it on MAUI
As long as we don't change/add/remove public APIs we're still open for bugfixes! Of course a contribution if this impacts you is much appreciated!