Skip to content

Build the conversation list addresses off the main thread - #2246

Draft
mpretty-cyro wants to merge 2 commits into
devfrom
fix/home-conversation-list-off-main
Draft

mpretty-cyro wants to merge 2 commits into
devfrom
fix/home-conversation-list-off-main

Conversation

@mpretty-cyro

Copy link
Copy Markdown
Collaborator

Contributor checklist

  • I have tested my contribution on these devices:
  • Virtual device: Pixel 6 profile, API 37 (arm64), play flavour, debug
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

ANR cluster with the main thread Blocked in SQLiteOpenHelper.getReadableDatabase, from HomeActivity.onCreate →
DefaultConversationRepository.conversationListAddressesFlow → ConfigFactory.ensureUserConfigsInitialized →
ConfigDatabase.retrieveConfigAndHashes, while another thread is still doing the first database open (setJournalMode).
The home screen shows with an empty list and the app is then killed for not responding.

conversationListAddressesFlow is now flowOn(Dispatchers.Default), so no collector runs its config and database work on
its own thread.

Testing: reproduced on an emulator with a debug-only 12s delay in the first database open (not in this PR): a cold launch ANR'd on dev ("Application does not have a focused window") with the main thread stuck for 12s in ConfigDatabase.retrieveConfigAndHashes ← conversationListAddressesFlow. With this change, across three runs: no main-thread database access, no ANR, and the list loads once the open finishes.

HomeViewModel collects conversationListAddressesFlow on the main thread
as the home screen opens. Its first emission initialises the user
configs, which reads ConfigDatabase and so waits for the database to
open. When that first open is slow, the home screen sat with an empty
list until the app was killed for not responding at launch.

@mpretty-cyro mpretty-cyro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant