Stop redrawing every conversation row each second

The conversation's mouse handlers were a new object on every render, so
the memoized rows re-rendered on each 1s clock tick, rebuilding every
reply's markdown. In a long session that grew native memory by about
1 GB an hour. Keep the object stable so rows render only when they change.
This commit is contained in:
Callum Alpass committed 2026-11-04 00:11:21 +11:00
1 parent 00df9c396a
commit ef79c2f915
1 file changed
+13 -10
+13 -10
View File
@@ -1142,21 +1142,24 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
const groups = useMemo(() => (mode === "palette" ? messageMatchGroups(paletteGroups({ query: paletteQuery, commands, snapshot: paletteSnapshot, now }), paletteSearch.result, paletteSnapshot, paletteQuery, now) : []), [mode, paletteQuery, commandKey, paletteSnapshot, paletteSearch.result]); const groups = useMemo(() => (mode === "palette" ? messageMatchGroups(paletteGroups({ query: paletteQuery, commands, snapshot: paletteSnapshot, now }), paletteSearch.result, paletteSnapshot, paletteQuery, now) : []), [mode, paletteQuery, commandKey, paletteSnapshot, paletteSearch.result]);
const entries = paletteEntries(groups); const entries = paletteEntries(groups);
// The mouse in the conversation: stable callbacks, since its rows are memoized. // The mouse in the conversation: stable callbacks in a stable object, since its rows are memoized.
const conversationMouse: ConversationMouse = { // A new object each render re-rendered every row, and every reply's markdown, each second.
selectTurn: useEvent((messageId: string) => turns.select(messageId)), const selectTurn = useEvent((messageId: string) => turns.select(messageId));
toggleFold: useEvent((id: string) => const toggleFold = useEvent((id: string) =>
setExpandedIds((previous) => { setExpandedIds((previous) => {
const next = new Set(previous); const next = new Set(previous);
if (!next.delete(id)) next.add(id); if (!next.delete(id)) next.add(id);
return next; return next;
}), }),
), );
loadEarlier: useEvent(() => loadEarlier()), const loadEarlierClick = useEvent(() => loadEarlier());
menu: useEvent((target: ConversationTarget) => openConversationMenu(target)), const openMenu = useEvent((target: ConversationTarget) => openConversationMenu(target));
openTurnDiff: useEvent((checkpointTurnCount: number) => turns.openTurnDiff(checkpointTurnCount)), const openTurnDiff = useEvent((checkpointTurnCount: number) => turns.openTurnDiff(checkpointTurnCount));
click: useEvent((x: number, y: number) => openAt(x, y)), const click = useEvent((x: number, y: number) => openAt(x, y));
}; const conversationMouse = useMemo<ConversationMouse>(
() => ({ selectTurn, toggleFold, loadEarlier: loadEarlierClick, menu: openMenu, openTurnDiff, click }),
[selectTurn, toggleFold, loadEarlierClick, openMenu, openTurnDiff, click],
);
const copy = (label: string, text: string) => { const copy = (label: string, text: string) => {
void clipboard.copy(text); void clipboard.copy(text);
say(`Copied ${label}`); say(`Copied ${label}`);