Skip to content

Optimized threads conversation view.#62

Open
akwotom wants to merge 2 commits into
smswithoutborders:masterfrom
akwotom:fix/ui-jank
Open

Optimized threads conversation view.#62
akwotom wants to merge 2 commits into
smswithoutborders:masterfrom
akwotom:fix/ui-jank

Conversation

@akwotom

@akwotom akwotom commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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.

  1. Contact name is fetched and cached, instead of having to call the system lookup APIs repeatedly.
  2. When a contact name is being fetched for a Sender ID (e.g MTN MoMo), the process is immediately short-circuited, because most devices cannot even store non-numeric contacts.

Contact Photo Fetch Optimization

  1. Because most devices cannot even contain non-numeric contacts, fetching the contact for a non-numeric address is immediately short-circuited.
  2. When contact photo is fetched, it is cached for faster re-use.

Caching Scope Optimization

Previously, frequently computed data were scoped to a local function within a LazyColumn, using remember() calls. However, as per the documentation of remember(), 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.

…ata. Optimized UX by preventing blocked conversations from showing up in the default inbox.
import androidx.room.Index
import androidx.room.PrimaryKey

@Immutable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is this for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't suppress lint

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All values here can be computed when the list is loading the items from paging source - no need to extend

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.

performance: laggy scrolling on the messages list

2 participants