Optimized threads conversation view.#62
Conversation
…ata. Optimized UX by preventing blocked conversations from showing up in the default inbox.
| import androidx.room.Index | ||
| import androidx.room.PrimaryKey | ||
|
|
||
| @Immutable |
There was a problem hiding this comment.
This allows jetpack to optimize areas that depend on the annotated data structure, by explicitly stating that the underlying fields will not change.
| var searchQuery: String? = null, | ||
| ) | ||
|
|
||
| @SuppressLint("FlowOperatorInvokedInComposition") |
There was a problem hiding this comment.
This was supposed to have been removed. It came from experiments I was running in order to find bugs.
I've addressed this in a new commit.
| val scope = rememberCoroutineScope() | ||
|
|
||
|
|
||
| var cachedExtras: HashMap<String, ThreadsExtended> = HashMap() |
There was a problem hiding this comment.
Frequently computed data about a Threads object are stored in a special class called ThreadsExtended. This data is persisted in the root function scope, so that it persists across re-compositions of the items within the LazyColumn.
| * The additional fields are mostly about values that are lazily computed and cached. | ||
| */ | ||
| @Immutable | ||
| data class ThreadsExtended( |
There was a problem hiding this comment.
All values here can be computed when the list is loading the items from paging source - no need to extend
In a bid to resolve #27, frequently computed pieces of data were identified, and optimized.
What Changed?
Blocked Numbers Optimization
Previously, we had been constantly looking up the database for each and every conversation on the list, to see if it's blocked.
The purpose of that lookup, was just to render a simple icon next to the conversation, showing that it is blocked.
In this update, the blocked numbers are altogether removed from the primary inbox, because after all, when the user decides to block a chat, he wouldn't want it in his primary inbox. Blocked chats only show in a special folder. This improves UX, and this saves us performance penalties.
Contact Name Fetch Optimization
Instead of constantly computing the contact name, necessary optimizations were made.
Contact Photo Fetch Optimization
Caching Scope Optimization
Previously, frequently computed data were scoped to a local function within a
LazyColumn, usingremember()calls. However, as per the documentation ofremember(), values are "forgotten" when the scope is no longer active.In this update, values are cached in the parent scope, and persisted across several re-composes of the LazyColumn items.