perf(ios/chat): skip re-rendering unchanged bubbles while typing#3454
Merged
Conversation
ChatView.body renders the composer's $draft state and the full message list in the same view body. Each MessageBubble hosts a MarkdownWebView (WKWebView), so every keystroke invalidated ChatView.body and re-diffed every WebView-backed bubble — producing per-character typing lag that worsened with thread length. Make MessageBubble Equatable over only its render-affecting value inputs (message, isGroup, familiar id, isLast, operator name/avatar, and the presence of optional action closures) and mark it .equatable() in the ForEach. SwiftUI now short-circuits unchanged bubbles, so a keystroke no longer re-renders the transcript. Streaming still re-renders only the active bubble (its text changes each token). Verified: xcodebuild build (scheme CovenCave, iOS Simulator) succeeds.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets iOS chat typing latency by preventing SwiftUI from re-diffing/re-rendering unchanged MessageBubble views (each hosting a WKWebView) on every composer keystroke, using Equatable + .equatable().
Changes:
- Added
Equatableconformance toMessageBubbleusing a subset of inputs intended to reflect render-affecting state. - Applied
.equatable()toMessageBubbleinstances inChatView’sForEachmessage list to enable SwiftUI short-circuiting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/ios/CovenCave/CovenCave/Views/MessageBubble.swift | Adds Equatable conformance to allow skipping updates for unchanged bubbles. |
| apps/ios/CovenCave/CovenCave/Views/ChatView.swift | Wraps each MessageBubble with .equatable() inside the message list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First PR in the iOS performance-optimization pass. Fixes slow/laggy typing in the chat composer.
Root cause
ChatView.bodyrenders the composer's@State draftand the full message list (LazyVStackForEachofMessageBubble) in the same view body. EachMessageBubblehosts aMarkdownWebView(WKWebView). Every keystroke mutateddraft→ invalidatedChatView.body→ SwiftUI re-diffed every WebView-backed bubble → per-character typing lag that worsened with thread length.Fix
MessageBubble: addedEquatableconformance over only render-affecting value inputs (message, isGroup, familiar id, isLast, operator name/avatar, and presence of the optional action closures). Closures are excluded — they capture fresh state each render but don't change what's drawn; optional-action closures compared by presence since that toggles which buttons appear.ChatView: added.equatable()to the bubble in theForEach.SwiftUI now short-circuits unchanged bubbles, so a keystroke no longer re-renders the transcript. Streaming still re-renders only the active bubble (its
textchanges each token →==returns false for that one).Verification
xcodebuild build(schemeCovenCave, iOS Simulator) → BUILD SUCCEEDED, no new warnings/errors.@Statein the bubble (replyDrag/mdHeight/markdownFailed) is preserved across equality skips — identity is pinned by.id(message.id).Blast radius
Small — 2 files, +23 lines, no behavior change beyond render skipping. Already shipped to TestFlight as build
2026071803and validated.Notes
CI (
ci.yml) does not build the native Swift app; localxcodebuildis the iOS verification gate. Follow-up perf PRs (WebView reuse, streaming token coalescing, off-main thread persistence, async startup) will land separately.