Skip to content

Fix chat input lag in long chats#137

Open
mcintyre94 wants to merge 1 commit into
mainfrom
check-chat-input-lag-issue-c8145021
Open

Fix chat input lag in long chats#137
mcintyre94 wants to merge 1 commit into
mainfrom
check-chat-input-lag-issue-c8145021

Conversation

@mcintyre94

Copy link
Copy Markdown
Owner

Summary

  • Replace VStack with LazyVStack in the chat message list so only visible messages are rendered, instead of all N messages on every re-render
  • Move the inputText draft-save onChange observer from ChatView into ChatInputBar, so that ChatView no longer re-renders on every keystroke

Root causes

1. Eager VStack — the message list used VStack, which renders every message upfront regardless of visibility. With a long chat, any re-render (including keystrokes) caused SwiftUI to evaluate the full message list.

2. ChatView observed inputText.onChange(of: viewModel.inputText) in ChatView.body registered ChatView as an observer of inputText. Every keystroke invalidated ChatView.body, triggering a full re-evaluation of all those message views. With a long chat, this was proportionally more expensive.

Test plan

  • Type in the input bar with a long chat open — should feel responsive with no lag
  • Scroll up through history — older messages load on demand correctly
  • Send a message and verify streaming still auto-scrolls to bottom
  • Draft auto-save still fires (500ms debounce) when typing
  • Stop/interrupt still works during streaming

🤖 Generated with Claude Code

Switch the message list from VStack to LazyVStack so only visible
messages are rendered, and move the inputText draft-save observer into
ChatInputBar so that ChatView no longer re-renders on every keystroke.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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