perf(chat): smooth stream rendering - #1954
Conversation
📝 WalkthroughWalkthroughThe PR optimizes artifact streaming parsing, stabilizes repeated chat-search highlighting, and refactors ChatPage streaming display and scroll coordination. It also adds issue specifications and focused tests for parser caching, highlight reuse, message caching, and streaming behavior. ChangesArtifact parsing optimization
Chat search highlight stability
Streaming rendering and scroll coordination
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant ChatPage
participant MessageListRow
participant ResizeObserver
participant useMessageWindow
ChatPage->>MessageListRow: render streaming message
MessageListRow->>ResizeObserver: report measured height
ResizeObserver->>useMessageWindow: update virtual-window measurements
useMessageWindow->>ChatPage: return viewport updates
ChatPage->>ChatPage: coalesce programmatic bottom scroll
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/composables/useArtifacts.ts (1)
97-98: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winUnclosed-artifact regex requires
title/identifier/typeand scans full content via.*+/s.Two concerns on this hot path:
- The three lookaheads use greedy
.*with thesflag, so each match attempt scans the entire remaining content (including artifact body) — partially reintroducing the linear-per-scan cost this PR targets, and allowing attributes located in the body to satisfy the lookaheads.ARTIFACT_CLOSED_REaccepts any attribute set (parseAttributesdefaults missing ones), butARTIFACT_UNCLOSED_REmatches only when all three attributes are present. A streaming artifact whose opening tag lackstitleis treated as plain text instead of aloadingartifact, which can surface the raw tag during streaming.Consider deriving the unclosed part from the opening-tag substring (as
buildUnclosedArtifactPartalready does) rather than encoding required attributes in lookaheads.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/renderer/src/composables/useArtifacts.ts` around lines 97 - 98, The ARTIFACT_UNCLOSED_RE pattern incorrectly scans the artifact body and requires title, identifier, and type. Update the unclosed-artifact handling to derive attributes from only the opening-tag substring, reusing the approach in buildUnclosedArtifactPart, and allow missing attributes consistently with ARTIFACT_CLOSED_RE so incomplete streaming artifacts still produce loading output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/renderer/src/lib/chatSearch.ts`:
- Around line 118-120: Update the chat-search root state handling around
setAppliedSearchQuery and related query-change logic to preserve applied-query
state for plain DocumentFragment roots that lack the data-chat-search-root
attribute. Store fragment state in a WeakMap<ParentNode, string>, continue using
the attribute for element roots, and ensure later query changes invoke
clearChatSearchHighlights so stale marks are rebuilt. Add a regression test
covering successive queries on a plain DocumentFragment.
---
Nitpick comments:
In `@src/renderer/src/composables/useArtifacts.ts`:
- Around line 97-98: The ARTIFACT_UNCLOSED_RE pattern incorrectly scans the
artifact body and requires title, identifier, and type. Update the
unclosed-artifact handling to derive attributes from only the opening-tag
substring, reusing the approach in buildUnclosedArtifactPart, and allow missing
attributes consistently with ARTIFACT_CLOSED_RE so incomplete streaming
artifacts still produce loading output.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a10d5818-ed4a-46a4-b0c9-3de225cb0466
📒 Files selected for processing (10)
docs/issues/artifact-streaming-parse-hotspot/spec.mddocs/issues/chat-search-highlight-flicker/spec.mddocs/issues/chat-stream-scroll-feedback-loop/spec.mddocs/issues/display-messages-streaming-hot-path/spec.mdsrc/renderer/src/composables/useArtifacts.tssrc/renderer/src/lib/chatSearch.tssrc/renderer/src/pages/ChatPage.vuetest/renderer/components/ChatPage.test.tstest/renderer/composables/useArtifacts.test.tstest/renderer/lib/chatSearch.test.ts
Summary by CodeRabbit
Performance Improvements
Bug Fixes
Documentation