Skip to content

perf(desktop): stop idle chat re-renders — memo ChatView + stable tile props (salvage #38470) - #77661

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:salvage/38470-idle-rerender
Aug 3, 2026
Merged

perf(desktop): stop idle chat re-renders — memo ChatView + stable tile props (salvage #38470)#77661
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:salvage/38470-idle-rerender

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Context

Idle chat surfaces were re-rendering constantly: a dep-less useEffect(() => runtime.setAdapter(store)) ran on EVERY render of the chat surface, and ChatView — the whole chat shell — was un-memoized while its tile caller passed fresh inline arrow props on each render, so every idle tick (now-tickers, unrelated store updates) re-rendered the entire chat tree. WHO: everyone with a chat open; the cost scales with tiles/panes mounted.

What this does

  • Gates the adapter re-sync on [runtime, store] — behavior-preserving because __internal_setAdapter early-exits when the store is unchanged (verified at the early-exit site); the effect now simply skips the call instead of making a no-op one every render.
  • Wraps ChatView in memo() and hoists session-tile's inline arrow props (onAddUrl, onPasteClipboardImage, onPick*, onRemoveAttachment, onRetryResume, noop pin/delete handlers, the transcribe wrapper) to useCallbacks/module constants so the memo actually holds.
  • Adds a render-count regression test: with a mocked Thread counting renders, an unrelated parent re-render no longer re-renders the chat shell.

Provenance

Re-derive of #38470 by @hdd69 (authorship preserved on the commit; attribution mapping merged in #77641). The original PR is unpickable — its main target file desktop-controller.tsx no longer exists after the contrib/ surfaces refactor, and its branch carries 3 merge commits — but all three of its ideas are alive on today's main and are applied here at their new homes (session-tile.tsx now owns the ChatView call site).

Measured impact

Render-count proof at the test level (stated substitution for CPU%): the new test fails on main (unrelated parent render re-renders the chat shell) and passes with the memo chain — that delta is the entire class of idle re-renders eliminated. 8 tests green across chat/index + incremental-external-store-runtime; mutation check: reverting index.tsx fails the render-count test, restore green.

Closes #38470.

… props, gated adapter re-sync

Re-derive of PR NousResearch#38470 on today's main (its target file desktop-controller.tsx no longer exists after the contrib/ refactor; the three surviving ideas are applied at their new homes):

- incremental-external-store-runtime: the dep-less setAdapter effect ran every render; gate on [runtime, store] — behavior-preserving because __internal_setAdapter early-exits on identical store.
- ChatView is now memo()d, and session-tile hoists its inline arrow props to useCallbacks/module constants so the memo actually holds.
- Render-count regression test (mocked Thread) proves an unrelated parent re-render no longer re-renders the chat shell.

Credit: idea and original implementation by @hdd69 in NousResearch#38470.
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 3, 2026 12:40
@kshitijk4poor
kshitijk4poor merged commit 82fd574 into NousResearch:main Aug 3, 2026
34 checks passed
@alt-glitch alt-glitch added type/perf Performance improvement or optimization P3 Low — cosmetic, nice to have comp/desktop Electron desktop app (apps/desktop/*) labels Aug 3, 2026
@kshitijk4poor
kshitijk4poor deleted the salvage/38470-idle-rerender branch August 5, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants