Skip to content

⚡ Bolt: Optimize ChatMessageItem re-renders with React.memo#29

Draft
Psyborgs-git wants to merge 1 commit intomainfrom
bolt/optimize-chat-message-item-12431176547593783766
Draft

⚡ Bolt: Optimize ChatMessageItem re-renders with React.memo#29
Psyborgs-git wants to merge 1 commit intomainfrom
bolt/optimize-chat-message-item-12431176547593783766

Conversation

@Psyborgs-git
Copy link
Owner

💡 What: The ChatMessageItem component in @orch/web-ui was wrapped with React.memo and 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 sessions array is replaced, which triggers a re-render of ChatMessagesList. Since ChatMessageItem is 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.memo ensures 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:

  1. Open the Chat UI and create a long conversation with multiple turns.
  2. Ask the AI agent a long question that streams a response.
  3. Observe React Profiler: ChatMessageItem components 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

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>
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant