perf(mailbox): remember() per-row relative-time formatting to cut per-recomposition allocation #213

Closed
opened 2026-07-03 14:51:39 +00:00 by JMR-dev · 0 comments
JMR-dev commented 2026-07-03 14:51:39 +00:00 (Migrated from github.com)

Source: perf audit of the Paging 3 usage (finding #2).

MessageRow formats the per-row relative timestamp via DateUtils.getRelativeTimeSpanString un-remembered, so it re-reads System.currentTimeMillis() and allocates a fresh String on every recomposition of the row (selection toggles, scroll settle, etc.).

Location: formatTimestamp(message.timestampMillis) at app/src/main/kotlin/org/libremail/ui/mailbox/MailboxScreen.kt:552 (formatter defined at :819).

Fix: wrap in remember(message.timestampMillis) { formatTimestamp(...) }. (Optionally also remember the avatar initial at :596.) If exact freshness matters, key on a coarse time tick rather than recomputing every frame.

**Source:** perf audit of the Paging 3 usage (finding #2). `MessageRow` formats the per-row relative timestamp via `DateUtils.getRelativeTimeSpanString` **un-`remember`ed**, so it re-reads `System.currentTimeMillis()` and allocates a fresh `String` on **every recomposition** of the row (selection toggles, scroll settle, etc.). **Location:** `formatTimestamp(message.timestampMillis)` at `app/src/main/kotlin/org/libremail/ui/mailbox/MailboxScreen.kt:552` (formatter defined at `:819`). **Fix:** wrap in `remember(message.timestampMillis) { formatTimestamp(...) }`. (Optionally also `remember` the avatar initial at `:596`.) If exact freshness matters, key on a coarse time tick rather than recomputing every frame.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: JMR-dev/LibreMail#213