Repository navigation
Coalesce conversation reloads instead of restarting the loader - #2243
Merged
Merged
Conversation
Every reload trigger called restartLoader, which abandons the running load without stopping it. Its query holds a database connection until the cursor window is filled, so during bursts of message, reaction or attachment changes several loads ran at once (up to four in ANR samples) and the main thread waited for a connection while binding rows. Signal a content change on the existing loader instead, which runs one load at a time; restart only when the thread ID has changed.
A recreated activity found the retained loader and only signalled a content change, so its own callbacks never received a load and the conversation stayed empty. Each instance now restarts the loader once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contributor checklist
playflavour,debugFixes #1234syntaxDescription
In the same ANR cluster, the main thread waits for a connection while binding conversation rows
(
ConversationAdapter.getItemViewType/onBindItemViewHolder→MmsDatabase.Reader.getQuote). The connections are held byseveral
ConversationLoaderloads at once (up to fourModernAsyncTaskthreads ingetCount()/fillWindow).restartConversationLoader()calledLoaderManager.restartLoader, which abandons the running load without stopping it, so eachreload trigger (debounced message, reaction and attachment changes) added another concurrent query. It now signals
onContentChanged()on the existing loader when the thread ID hasn't changed, soAsyncTaskLoaderruns one load at a time andcoalesces the rest; it still restarts when the thread ID changes.
Each activity instance still restarts the loader once before it starts coalescing. The loader survives a configuration change, but only
restartLoader/initLoaderbind it to the new instance's callbacks; without that, rotating or switching theme left the conversation empty.This reduces contention; it doesn't remove the main-thread row reads in the cursor adapter.
Testing: on an emulator with a debug-only delay in
ConversationLoader(not in this PR) and a concurrency counter, eight rapid sends ran up to 3 loads at once ondev, and at most 1 with this change; the list still updated. Rotating an open conversation and rotating back keeps its messages, as ondev. The adapter-bind ANR itself wasn't reproduced.