Skip to content

perf: memoize chat message rendering#41

Merged
charlesrhoward merged 1 commit intomainfrom
codex/feat-29-memoize-chat-message-rendering
Feb 21, 2026
Merged

perf: memoize chat message rendering#41
charlesrhoward merged 1 commit intomainfrom
codex/feat-29-memoize-chat-message-rendering

Conversation

@charlesrhoward
Copy link
Contributor

@charlesrhoward charlesrhoward commented Feb 21, 2026

Summary

  • memoize chat message row rendering so unchanged messages skip rerenders
  • memoize assistant markdown blocks so unchanged text is not reparsed
  • keep visual output and behavior unchanged

Closes #29


Note

Low Risk
Performance-only refactor in a UI component; main risk is subtle stale renders if the signature misses a message change (e.g., non-text/file parts).

Overview
Refactors ChatMessages rendering to skip re-rendering unchanged messages by introducing memoized MessageRow components keyed by a computed parts signature (text/file only) and precomputing {message, signature} via useMemo.

Also memoizes assistant markdown rendering (AssistantMarkdown) so identical assistant text isn’t re-parsed by ReactMarkdown, while preserving existing handling for text, image/file parts (with URL sanitization), and tool parts.

Written by Cursor Bugbot for commit 0db3fb1. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drawit Ready Ready Preview, Comment Feb 21, 2026 10:11pm

Request Review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e669231095

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

.filter((part) => part.type === "text" || part.type === "file")
.map((part) => {
if (part.type === "text") {
return `text:${part.text}`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use collision-proof signatures for memoized message rows

The memoization key built here is ambiguous because raw message text is concatenated with hardcoded delimiters (|, :) and no escaping. Different parts arrays can produce the same signature (e.g. [{text:"a"},{text:"b"}] and [{text:"a|text:b"}] both serialize to text:a|text:b), so MessageRow may skip rerendering even though the rendered structure changed. This can surface when streamed/normalized assistant parts are regrouped and causes stale markdown/image output until some unrelated prop changes.

Useful? React with 👍 / 👎.

@charlesrhoward charlesrhoward force-pushed the codex/feat-29-memoize-chat-message-rendering branch from e669231 to 0db3fb1 Compare February 21, 2026 22:10
@charlesrhoward charlesrhoward merged commit 15545b7 into main Feb 21, 2026
4 checks passed
@charlesrhoward charlesrhoward deleted the codex/feat-29-memoize-chat-message-rendering branch February 21, 2026 22:15
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.

Performance: Memoize chat message rendering to reduce markdown rerenders

1 participant