Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/mobile
Steps to reproduce
- Open a thread whose agent is producing tool calls (for example "make 200 separate shell calls, each
echo step N; sleep 2"). - Background the app for 45 s, then return.
- Log renders of
ThreadRouteContent,ThreadDetailBody,ThreadFeed,ThreadComposerandAssistantMarkdownContent(or profile the resume).
Expected behavior
Connection-state, sync-status and unrelated store changes re-render only what displays them. Catch-up events re-render the feed rows that changed.
Actual behavior
Every render of the route rebuilds every prop of the thread screen, so the whole screen re-renders on each connection, sync and status change. During one resume, every visible assistant message re-rendered with identical props on each connection change: 378 AssistantMarkdownContent renders in a 45 s capture.
The React Compiler output shows why. Its memo scopes are dropped (pruned) in these places:
useThreadComposerState: derived values are computed between hook calls (useAtomValue,useNowMinuteMs,useComposerAttachmentActions, ...). Values such as(map[key] ?? []).filter(...)are then passed on to other calls, so their scopes span hooks and are pruned.selectedThreadFeed,selectedThreadActivityRun,onSendMessageand the returned object are rebuilt on every render, even when the detail is unchanged.ThreadRouteContent:Option.getOrNull(selectedThreadDetailState.data)produces a value the compiler treats as mutable. Its later method calls (.messages.find,resolveMergeBackTargetThreadId(...)) merge most of the component into one scope that spans hooks, which gets pruned.renderThreadRouteBody()is a local function called during render, which keeps everything it captures unmemoized.contentPresentationis passed on tothreadSyncStatusLabelafter auseDelayedStatuscall.
ThreadDetailBody:scopedThreadKey(...)(an opaque call) has the same effect for every callback that capturesselectedThreadKey, includingonJumpedToMessageandonFreshSession.props.onSendMessage(...)andprops.onChangeDraftMessage(...)makehandleSendMessageandhandleUseArtifactTemplatedepend on all ofprops.
useLinkedEnvironments(null): called by every message without thread links, it still subscribes to the whole environment presentation map throughuseEnvironments(), so every connection change re-renders all visible markdown.
Fixes that restore memoization, with behavior unchanged:
- Call hooks before deriving values in
useThreadComposerState. - Read
Option.isSome(x) ? x.value : nullinstead of callinggetOrNull. - Inline the body JSX.
- Move the one hook above
contentPresentation. - Pass
selectedThreadKeyas a prop. - Destructure the two prop callbacks.
- In
useLinkedEnvironments, read presentations from an empty atom whenenvironmentIdis null.
I checked each one against [email protected] output. With render tracing on, route renders stop cascading into the thread screen, and assistant messages render only on mount.
Two GT costs ran on every one of those renders. LocaleConfig.requiresTranslation validates both locales through Intl on each call. gt-i18n's hashMessage computes SHA-256 per msg() call and per lookup. Together they took ~350 ms per resume in a production-mode Hermes profile. A cache on each (pnpm patches) removed them, and JS work from foreground to thread live dropped from 2238 ms to 1589 to 1717 ms.
Impact
Major degradation or frequent failure
Version or commit
Files as of c3a330d (ThreadRouteScreen.tsx, ThreadDetailScreen.tsx, use-thread-composer-state.ts, state/peerLinks.ts)
Environment
Android 17 emulator (production and dev bundles) and Pixel 9 Pro (release build)
Logs or stack traces
Render trace excerpt, before (each line is one render, with the props that changed):
RouteContent ["composer"] composer ["selectedThreadFeed","selectedThreadActivityRun","onSendMessage", ...] detailState []
DetailBody.props ["header","contentPresentation","screenTone","selectedThreadFeed","onSendMessage","onReconnectEnvironment"]
AMC [] (x25 on each connection change)
Upstream
The two GT costs are reported as generaltranslation/gt#2992.
Activity
joei4cm commentedon Nov 22, 2026
Taking this — the app-side memoization set from the list above: hook order in
useThreadComposerState, theOption.getOrNull/renderThreadRouteBody/contentPresentationscopes inThreadRouteScreen, the prop captures inThreadDetailBody, anduseLinkedEnvironments(null)reading an empty atom. All behavior-preserving, as analyzed.Out of scope here: the two GT i18n costs. Those are
generaltranslation/gt#2992and would be a dependency patch rather than an app fix.