⚡ Bolt: Optimize ChatMessageItem re-renders with React.memo#29
⚡ Bolt: Optimize ChatMessageItem re-renders with React.memo#29Psyborgs-git wants to merge 1 commit intomainfrom
Conversation
Implemented React.memo with a custom equality function on ChatMessageItem to prevent unnecessary re-renders of older chat messages when new chunks are streaming in. This dramatically improves UI performance for long chat sessions. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: The
ChatMessageItemcomponent in@orch/web-uiwas wrapped withReact.memoand a custom equality function was added to compare specific props (msg.id,msg.content,msg.toolCalls,msg.toolResults,disabledActions,isGrouped).🎯 Why: When a new chunk arrives during an AI chat response, the entire
sessionsarray is replaced, which triggers a re-render ofChatMessagesList. SinceChatMessageItemis a heavy component (rendering markdown, tool logs, syntax highlighting), re-rendering every previous message in the chat history on every chunk caused severe UI lag and jank as the chat history grew.React.memoensures that only the active streaming message (whose content is changing) and actually modified messages are re-rendered.📊 Impact: Reduces CPU usage and unnecessary re-renders in the ChatView by ~O(N) (where N is the number of previous messages in the chat session). This will result in significantly smoother scrolling and streaming experience in long conversation contexts.
🔬 Measurement:
ChatMessageItemcomponents for prior messages will now show "Did not render" instead of re-rendering on every token chunk.PR created automatically by Jules for task 12431176547593783766 started by @Psyborgs-git