Skip to content

perf(web): reuse sessions reference to stop sidebar re-render on streaming deltas - #1113

Merged
wbxl2000 merged 1 commit into
mainfrom
perf/web-sidebar-sessions-ref
Jun 25, 2026
Merged

perf(web): reuse sessions reference to stop sidebar re-render on streaming deltas#1113
wbxl2000 merged 1 commit into
mainfrom
perf/web-sidebar-sessions-ref

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Problem

During long streaming replies the web UI's session sidebar re-renders on every single token, contributing to main-thread jank. Profiling attributed ~2.2s/frame to the sidebar computeds (sessionsForView / workspaceGroups / mergedWorkspaces).

Root cause: the event reducer's cloneState() did sessions: [...s.sessions] on every event, so the sessions array reference changed on every high-frequency event (e.g. assistantDelta, toolOutput, taskProgress) even though those events never touch sessions. Since the sidebar computeds depend on rawState.sessions, the changed reference dirtied all of them each token.

What changed

cloneState() now reuses the existing sessions reference for events that do not change sessions. Every session-mutating case in the reducer already builds its own array via [...] / .map / .filter, so sharing the reference is safe — events that genuinely change sessions still produce a new array.

This is a small, focused subset of the larger streaming-render work, split out so it can be reviewed and merged on its own. It does not change any rendering or event-routing behavior; it only avoids invalidating the sidebar on unrelated events.

Checklist

  • I have read the CONTRIBUTING document.
  • I have explained the problem above (focused bug/perf fix with a small diff — no separate issue).
  • I have added tests that prove the fix works (reduceAppEvent sessions reference stability: reuses the array when sessions are untouched, produces a new array when sessions change).
  • Added a changeset (@moonshot-ai/kimi-code: patch).
  • No doc update needed — internal state-management change, no user-visible docs (gen-docs N/A).

@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e618584

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@e618584
npx https://pkg.pr.new/@moonshot-ai/kimi-code@e618584

commit: e618584

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: e618584d3a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000
wbxl2000 merged commit 6194d3f into main Jun 25, 2026
9 checks passed
@wbxl2000
wbxl2000 deleted the perf/web-sidebar-sessions-ref branch June 25, 2026 18:24
@github-actions github-actions Bot mentioned this pull request Jun 25, 2026
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