Skip to content

perf: refresh sidebar age labels without rendering the list - #1191

Open
kogekiplay wants to merge 2 commits into
spacering-net:mainfrom
kogekiplay:perf/sidebar-relative-time-labels
Open

kogekiplay wants to merge 2 commits into
spacering-net:mainfrom
kogekiplay:perf/sidebar-relative-time-labels

Conversation

@kogekiplay

@kogekiplay kogekiplay commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The sidebar's minute tick currently re-renders the virtualizer even when every displayed age label stays the same. Keep the shared 60-second clock and let each visible age label subscribe to its formatted text. Updating a label no longer re-renders the list or its conversation card.

For a native check of the actual patch, one signed WKWebView test host loaded the dependency-matched control and patched frontend resources in two serial, invisible 12-minute runs. Each had four sidebar rows, 358 physical-footprint samples, and 11 observable clock firings. Native command totals and DOM element counts at both endpoints matched. From the first to the last three-minute bin, footprint Q1 rose 1.81 MiB in the control and 0.80 MiB with the patch. Tick intervals with a rise of at least 1 MiB fell from six to three; several excursions recovered on the next sample. This measures one hidden test pair and does not establish the long-term effect in visible production windows.

The sidebar regression covers both cases: a minute with unchanged labels does not re-render the list or cards, and a later tick still updates the label when its formatted age changes. Formatting, lint, all 13,126 frontend tests, and the static export build (including TypeScript) passed. All ten jobs in the PR CI run passed.

@xintaofei

Copy link
Copy Markdown
Collaborator

Verdict: the approach holds, and this is ready.

Before this change, a useState clock in SidebarConversationList re-rendered the whole list and its Virtualizer every minute, even when no label changed. Now the list owns a small external clock (src/components/conversations/sidebar-relative-time.tsx:4) and starts its interval. Each card's SidebarRelativeTime reads its own label through useSyncExternalStore. Because the snapshot is the formatted string, a tick re-renders only the labels whose text actually changes. src/components/message/activity/use-live-elapsed.ts already uses the same pattern, so this matches the rest of the codebase.

Checked:

  • subscribe stays stable. React re-reads the string snapshot after subscribing, so a tick that lands between render and subscription is not lost. The interval is cleared on unmount.
  • The one production call site still uses conversationRowTimestamp(row, sortMode). That covers Folders, Pinned, Recent, Chat and sub-session rows. Running and cancelled badges still take priority, and timestamps that can't be parsed still show no label.
  • Card memoization is unaffected: the clock object never changes and the timestamp prop is a string.
  • The new regression test fails if the list is reverted to the old code (Virtualizer render count 2 vs 1), so it does guard the claim.

Changed on top: one docs-only commit. Two comments in src/components/conversations/sidebar-conversation-grouping.ts (on formatRelative and buildRows) still described the removed list-level now tick. They now describe the shared clock.

Non-blocking note: only the card unit tests use the card's timeLabel prop now. It's fine to keep as a fallback.

Verification: prettier and eslint are clean, the full vitest suite passes (13,126 tests), and the static export build (with type checking) passes. A second, independent review found no blocking issues.

The changes were pushed to this pull request (1 file, +7/-8).


🤖 Generated with Codeg

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.

2 participants