perf: memoize chat message rendering#41
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 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}` |
There was a problem hiding this comment.
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 👍 / 👎.
e669231 to
0db3fb1
Compare
Summary
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
ChatMessagesrendering to skip re-rendering unchanged messages by introducing memoizedMessageRowcomponents keyed by a computed partssignature(text/file only) and precomputing{message, signature}viauseMemo.Also memoizes assistant markdown rendering (
AssistantMarkdown) so identical assistant text isn’t re-parsed byReactMarkdown, 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.