Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a contained mobile performance refactor that preserves the existing feed derivation and inputs while stabilizing the rendered data array across unrelated renders. Its impact is limited to reducing redundant computation and list updates in the chat feed. No code changes detected at You can add or adjust custom eligibility rules. Learn more. |
c4b6491 to
7368992
Compare
Dismissing prior approval to re-evaluate 7368992
7368992 to
a997909
Compare
a997909 to
82e9d33
Compare
Note
Part of a series fixing values the React Compiler stopped caching after the mobile migrations. Each PR restructures the code so the compiler can cache it, without adding
useMemooruseCallback. Each is independent and can merge in any order:Note
🤖 Claude Opus 5.5 on behalf of Oliver
Problem
After the mobile React Compiler migration #21268,
ThreadFeed(apps/mobile/src/features/threads/ThreadFeed.tsx) computespresentedFeedas a plain value, and the compiler drops its cache scope without reporting an error. The compiler treatspresentedFeedas a fresh mutable array. Later calls such asresolveChatListAnchoredEndSpace(presentedFeed, …)might mutate it, so its range stretches across theuseLayoutEffect,useEffect, anduseRefcalls below it. A cache block can't span a hook call, so the compiler flattened the whole span from line 2097 to 2348. That pruned 17 values, includingpresentedFeed,anchoredEndSpace,setupAnchorIndex,listMountKey, and the toggle and copy handlers.As a result,
deriveThreadFeedPresentationreran on everyThreadFeedrender: copy feedback, row expand, and end-follow changes. Each of those renders also handed LegendList a newdataarray whilemaintainScrollAtEnd.on.dataChangewas on.Change
Move the derivation, together with the
feedCachestate it owns, into a smalluseThreadFeedPresentationhook. The compiler treats a hook's return value as frozen, so passingpresentedFeedto later calls no longer stretches its range across the hooks that follow. Inside the hook, nothing comes after the derivation, so the compiler caches it as a single block keyed on its inputs. This adds nouseMemo.Scope and approval
This is a focused regression fix that restores caching the compiler migration meant to keep, with no behavior change. It was split out of #21966 per the one-problem rule.
Verification
Compiler output. I compiled the file through
babel.config.jswith Metro's iOS release caller flags (thereactCompilerCoverage.test.tssetup) and a compiler logger:expandedTurnIds,expandedWorkGroups,feedCache, and the five feed props.ThreadFeedreadspresentedFeedfrom that hook.anchoredEndSpace,onCopyWorkRow, and the other handlers are back in$[n]cache slots.ThreadFeeddropped from 17 to 1. The remaining one is the existingduoColumnsexpression, which was also pruned on main.CompileErrorevents, andKNOWN_BAILOUTSis unchanged.Measurements. I ran the compiled
useThreadFeedPresentationextracted from the babel output against a synthetic 40-turn feed of about 400 entries. Each step uses the state ThreadFeed's handlers produce. Main runs the same expression unguarded, matching its compiled output.deriveThreadFeedPresentationcalls, main → this PRdata, main → this PRThe CPU saving per render is small. Thanks to the incremental
feedCache, each skipped call cost about 0.05–0.3 ms in Node on this machine. The larger effect is that LegendList no longer gets a newdataarray, which triggeredmaintainScrollAtEndon every one of these renders.Checks.
vp test run apps/mobile/src/reactCompilerCoverage.test.tspassed (894). Mobiletypecheckpassed.vp lintonThreadFeed.tsxshows no new warnings (25 before and after).Claude Opus 5.5 via Claude Code in T3 Code