perf: optimize agent stream view rendering

- Separate streaming item from FlatList data array to prevent full
  re-diffs on every streaming chunk
- Memoize renderStreamItem with useCallback
- Memoize AgentThoughtMessage component with React.memo

The main fix is rendering the streaming message in ListHeaderComponent
instead of prepending it to the data array, which was causing the
entire list to re-diff on every character streamed.
This commit is contained in:
Mohamed Boudra
2026-01-09 18:00:34 +07:00
parent 1a2498e9e7
commit b90c17a919
2 changed files with 102 additions and 103 deletions
+2 -2
View File
@@ -963,7 +963,7 @@ const agentThoughtStylesheet = StyleSheet.create((theme) => ({
},
}));
export function AgentThoughtMessage({ message, status = "ready" }: AgentThoughtMessageProps) {
export const AgentThoughtMessage = memo(function AgentThoughtMessage({ message, status = "ready" }: AgentThoughtMessageProps) {
const { theme } = useUnistyles();
const [isExpanded, setIsExpanded] = useState(false);
const markdownContent = useMemo(() => message?.trim() ?? "", [message]);
@@ -1102,7 +1102,7 @@ export function AgentThoughtMessage({ message, status = "ready" }: AgentThoughtM
isLoading={status !== "ready"}
/>
);
}
});
interface ToolCallProps {
toolName: string;