on main help sign in
fix(ui): optimize assistant message rendering to improve performance (#2258)
46ebd20Ayman Bagabas
internal/ui/chat/assistant.go+16−4
@@ -107,11 +107,23 @@ func (a *AssistantMessageItem) RawRender(width int) string {
107
107
108// Render implements MessageItem.
108// Render implements MessageItem.
109func (a *AssistantMessageItem) Render(width int) string {
109func (a *AssistantMessageItem) Render(width int) string {
110+ // XXX: Here, we're manually applying the focused/blurred styles because
111+ // using lipgloss.Render can degrade performance for long messages due to
112+ // it's wrapping logic.
113+ // We already know that the content is wrapped to the correct width in
114+ // RawRender, so we can just apply the styles directly to each line.
115+ focused := a.sty.Chat.Message.AssistantFocused.Render()
110− style := a.sty.Chat.Message.AssistantBlurred
116+ blurred := a.sty.Chat.Message.AssistantBlurred.Render()
117+ rendered := a.RawRender(width)
118+ lines := strings.Split(rendered, "\n")
119+ for i, line := range lines {
111− if a.focused {
120+ if a.focused {
112− style = a.sty.Chat.Message.AssistantFocused
121+ lines[i] = focused + line
122+ } else {
123+ lines[i] = blurred + line
124+ }
113 }
125 }
114− return style.Render(a.RawRender(width))
126+ return strings.Join(lines, "\n")
115}
127}
116
128
117// renderMessageContent renders the message content including thinking, main content, and finish reason.
129// renderMessageContent renders the message content including thinking, main content, and finish reason.