Repository navigation
Reuse message records across binds of the same conversation cursor - #2277
Draft
mpretty-cyro wants to merge 1 commit into
Draft
mpretty-cyro wants to merge 1 commit into
mpretty-cyro wants to merge 1 commit into
Conversation
Each bind built the full MessageRecord for its row and both neighbours, plus once more for getItemViewType, and every record parses its attachment, reaction and content JSON and looks up its sender without a cache. A screen of rows built about four records per row on every rebind. Records are now cached by position for the life of a cursor, so a bind builds only rows it hasn't seen, and rebinds that keep the cursor reuse them all. A new cursor clears the cache.
2 of 3 tasks
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,qaFixes #1234syntaxDescription
Slow frames in the conversation screen. Every message bind built the full
MessageRecordfor its own row, then again for the rows before and after it.getItemViewTypebuilt it once more. Building a record parses its attachment, reaction and content JSON and callsgetRecipientSync, which isn't cached. A screen of rows therefore built about four records per row on every rebind, and the cursor-swapnotifyDataSetChangedrebinds every visible row on each database change.ConversationAdapternow caches records by position for the life of a cursor. A bind builds only rows it hasn't seen yet. Rebinds that keep the cursor (selection, search, the last-sent marker) reuse all of them. A new cursor clears the cache, because the same position may now be a different row.MessageRecordhas no setters, so sharing one between binds is safe.One difference: a rebind that keeps the cursor now shows the sender details from when the row was first built. A sender's details changing without a cursor reload is already not refreshed for most rows, and the next message, reaction or thread change reloads the cursor.
Confidence: high that it removes the repeated work. The size of the gain on real devices isn't measured.
Testing: a local build of 1.33.9 with only this change and the album change (#2278) on top, against plain 1.33.9, on the same Note to Self (about 100 texts, one long message, about 20 image messages). I profiled the main thread with
simpleperfwhile running the same scripted scroll:getItemViewType: 9.3–10.0% of main-thread CPU before, 0.4–0.5% after.getRecipientSync: 3.8–4.4% before, 0.6–0.7% after.Frame stats from
dumpsys gfxinfodidn't change measurably, because the emulator's rendering dominates every frame.I also checked that selecting messages, deleting selected messages on this device, receiving new messages afterwards, and the long-press menu all behave as before.