perf(mobile): recycle the default v2 home list and scope the snooze minute tick #13149
Mergedjuliusmarmingemerged 9 commits into
main fromrefs/pull/13149/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/mobile/src/features/home/HomeScreen.tsx line 980Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -937,17 +950,16 @@937950 snoozeEnvironmentIds,938- threadListV2Items,939951 threadSearchMatchByKey,940952 titleRegenerationEnvironmentIds,941953 toggleSettledShelf,942954 toggleSnoozedShelf,943955 v2ProjectTitleByProjectKey,944956 props.searchQuery,945- nowMinute,946957 ],947958 );948959 const v2KeyExtractor = useCallback((item: ThreadListV2ListItem) => item.key, []);949960950- // FlatList treats a changed extraData identity as "re-render every visible951- // row", so an inline object literal would invalidate all rows on every952- // HomeScreen render.961+ // FlatList/LegendList treat a changed extraData identity as "re-render every962+ // visible row", so an inline object literal would invalidate all rows on963+ // every HomeScreen render — and the minute clock must stay out of it for964+ // the same reason: the clock text is precomputed per item instead.953965 const v2ExtraData = useMemo(apps/mobile/src/features/threads/threadListV2.ts line 342Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -276,0 +304,21 @@304+ value.type === "v2-settled-shelf"305+ );306+}307+308+/** Recycled-list equality for the flat v2 list (Home + iPad sidebar).309+ Item objects are rebuilt on every minute tick and every partition run;310+ without this the lists would consider every mounted row changed and311+ re-render all of them (each carrying a swipeable + a PR subscription).312+ The clock-derived fields are per-row precomputed text, so a minute tick313+ only flips equality on rows whose visible text (or snooze menu) actually314+ moved. Thread references are stable across rebuilds. */315+export function threadListV2ListItemsAreEqual(316+ previous: ThreadListV2ListItem,317+ item: ThreadListV2ListItem,318+): boolean {319+ switch (item.type) {320+ case "v2-thread":321+ return (322+ previous.type === "v2-thread" &&323+ previous.key === item.key &&324+ previous.item.thread === item.item.thread &&apps/mobile/src/features/home/HomeScreen.tsx line 980Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -937,17 +950,16 @@937950 snoozeEnvironmentIds,938- threadListV2Items,939951 threadSearchMatchByKey,940952 titleRegenerationEnvironmentIds,941953 toggleSettledShelf,942954 toggleSnoozedShelf,943955 v2ProjectTitleByProjectKey,944956 props.searchQuery,945- nowMinute,946957 ],947958 );948959 const v2KeyExtractor = useCallback((item: ThreadListV2ListItem) => item.key, []);949960950- // FlatList treats a changed extraData identity as "re-render every visible951- // row", so an inline object literal would invalidate all rows on every952- // HomeScreen render.961+ // FlatList/LegendList treat a changed extraData identity as "re-render every962+ // visible row", so an inline object literal would invalidate all rows on963+ // every HomeScreen render — and the minute clock must stay out of it for964+ // the same reason: the clock text is precomputed per item instead.953965 const v2ExtraData = useMemo(
- apps/mobile/src/features/home/HomeScreen.tsx line 1265Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1225,8 +1235,16 @@12251235 : "flex-1 bg-screen"12261236 }12271237 >1238+ {/* Same recycler the iPad sidebar and the legacy list use: cells are1239+ reused across data rebuilds and `itemsAreEqual` keeps a minute tick1240+ (or an unrelated shell update) from re-rendering untouched rows. */}12281241 <SwipeableScrollGateProvider enabled={swipeEnabled}>1229- <FlatList1242+ <LegendList12301243 data={threadListV2Items}12311244 renderItem={renderV2Item}12321245 keyExtractor={v2KeyExtractor}1246+ getItemType={(item) => item.type}1247+ itemsAreEqual={threadListV2ListItemsAreEqual}1248+ estimatedItemSize={ESTIMATED_THREAD_LIST_V2_ROW_HEIGHT}1249+ drawDistance={500}1250+ recycleItems
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/mobile/src/features/threads/threadOrder.ts lines 139 to 146OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -108,0 +126,21 @@126+export function computeThreadMoveAvailability(input: {127+ readonly ordered: readonly OrderRow[];128+ readonly allThreads?: readonly OrderRow[];129+ readonly section: PendingThreadOrder["section"];130+ readonly reorderableEnvironmentIds: ReadonlySet<EnvironmentId>;131+ readonly pendingOrder?: PendingThreadOrder | null;132+}): Map<string, ThreadMoveAvailability> {133+ const result = new Map<string, ThreadMoveAvailability>();134+ // A reorder in flight locks the whole list until its receipt lands.135+ if (input.pendingOrder != null) return result;136+ const rows = input.ordered;137+ const orderedIds = rows.map(rowId);138+ const indexById = new Map(orderedIds.map((id, index) => [id, index] as const));139+ const sourceRows = input.allThreads ?? input.ordered;140+ const keysById = new Map(141+ sourceRows.map((row) => [rowId(row), rowOrder(row, input.section).key] as const),142+ );143+ const isWritable = (id: string): boolean => {144+ const environmentId = id.slice(0, id.lastIndexOf(":"));145+ return input.reorderableEnvironmentIds.has(environmentId as EnvironmentId);146+ };
- apps/mobile/src/features/threads/threadOrder.ts line 158OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -108,0 +138,21 @@138+ const indexById = new Map(orderedIds.map((id, index) => [id, index] as const));139+ const sourceRows = input.allThreads ?? input.ordered;140+ const keysById = new Map(141+ sourceRows.map((row) => [rowId(row), rowOrder(row, input.section).key] as const),142+ );143+ // Composite row ids are not parseable — ids may themselves contain `:` — so144+ // writability maps through the row's own environmentId like the planner's.145+ const environmentById = new Map(146+ sourceRows.map((row) => [rowId(row), row.environmentId] as const),147+ );148+ const isWritable = (id: string): boolean => {149+ const environmentId = environmentById.get(id);150+ return environmentId !== undefined && input.reorderableEnvironmentIds.has(environmentId);151+ };152+ const visibleIds = new Set(orderedIds);153+ const reservedKeys = new Set(154+ [...keysById].flatMap(([id, key]) => (!visibleIds.has(id) && key != null ? [key] : [])),155+ );156+ // `planPinnedReorder`'s section-rewrite fallback writes every row in the157+ // section, so it is a viable plan for all rows or for none.158+ const bulkViable = orderedIds.every(isWritable);
juliusmarminge merged this151324b
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
db898a3· PR result:f8c3c40· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.