Skip to content

Stop the whole desktop UI re-rendering on every streaming update #153

Open
3 of 3 issues completed
Open

Description

@GoDiao

Summary

During a streaming reply, most of the desktop UI re-renders on every store update. The cause is coarse state updates combined with wide subscriptions:

  • updateSessionIn (desktop/src/stores/chatStore.ts:612-620) creates a new session object on every change.
  • Many components subscribe to that whole object, or to the whole store.

So a single text flush, a thinking delta, or the per-second timer re-renders the sidebar, the composer, the message list and the page itself.

Where it happens

  • Whole session object:
    • pages/ActiveSession.tsx:240
    • components/chat/MessageList.tsx:1222
    • components/chat/StreamingIndicator.tsx:39
    • components/chat/ChatInput.tsx:129
  • No selector at all, so they re-render on any change to any session:
    • components/chat/ChatInput.tsx:127
    • PermissionDialog.tsx:128
    • AskUserQuestion.tsx:64
  • Sidebar: subscribes to every session (components/layout/Sidebar.tsx:69) and rebuilds the running-session set each time (:188-197). So the 1,900-line sidebar re-renders on every delta of every session.
  • Thinking deltas are not batched: text and tool-input deltas go through a 50ms buffer, but thinking deltas update the store on each event (chatStore.ts:1309-1328). Each one rebuilds the whole render model in MessageList and re-renders every tool group through a new toolResultMap.
  • Elapsed timer: increments elapsedSeconds in the session state every second (chatStore.ts:850), which re-renders all of the above for the whole turn.

Tasks

Open to contributors, as sub-issues (comment on one to claim it):

Maintainer:

Done when

  • Each PR shows a before/after measurement: render counts from React Profiler, or a Safari Web Inspector timeline of a streaming reply.
  • No component stops updating when it should. Tests cover the fields each changed component relies on.
  • Desktop tests and typecheck pass.

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions