perf(renderer): reduce sustained CPU/energy impact and improve chat performance#3132
Draft
gantoine wants to merge 1 commit into
Draft
perf(renderer): reduce sustained CPU/energy impact and improve chat performance#3132gantoine wants to merge 1 commit into
gantoine wants to merge 1 commit into
Conversation
The renderer sat at 35-44% CPU with a very high syscall rate. Four independent sources, addressed here: Streaming re-renders: several always-mounted components subscribed to the whole session object (new identity every ~16ms during a turn) but read one scalar, so they re-rendered ~60fps. Add a narrow `useSessionSelector` and convert ModelSelector, QueuedMessagesDock, useFixWithAgent, TaskShellPanel; switch useNestedGenerationTaskIds to the signature-guarded sidebar map; and coalesce the deployed-agent chat stream into one store write per frame (the local-session path already batches this way). Polling/IPC: raise the per-terminal foreground-process poll 500ms -> 2000ms (~4x fewer IPC round-trips) and stop background-polling the inbox reviewer list when the window is unfocused. Animations: freeze CSS keyframe animations while the window is blurred or hidden (also stops ph-pulse's per-frame main-thread color repaint). Terminals: a hidden tab stays mounted and kept repainting an off-screen canvas at 60fps when it received output; coalesce hidden-terminal writes onto a 250ms timer instead of an animation frame. Generated-By: PostHog Code Task-Id: d8b8b39f-37df-47e1-8e8b-1411faede49d
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Contributor
|
Reviews (1): Last reviewed commit: "perf(renderer): cut sustained CPU/energy..." | Re-trigger Greptile |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
This PR reduces renderer process energy consumption by batching chat message updates and increasing terminal polling intervals, while also fixing state management bugs in git interactions and session handling.
What changed?
Performance improvements
Agent chat message batching (
agentChatService.ts): Messages from the agent stream are now coalesced into at most one store write per frame (16ms) instead of one per SSE event. This significantly reduces the frequency of state clones and re-renders when streaming tokens, cutting sustained CPU usage during active agent sessions.Terminal polling cadence (
terminal/identifiers.ts): IncreasedSHELL_PROCESS_POLL_INTERVAL_MSfrom 500ms to 2000ms. The foreground process poller drives IPC round-trips even when idle, and a 2-second label lag is imperceptible for typical process names. This reduces steady-state IPC/context-switch load ~4x while only flushing on actual name changes.Session map memoization (
useNestedGenerationTaskIds.ts): Replaced inline session map creation with a dedicateduseSidebarSessionMap()hook that provides a signature-guarded, stable reference. This prevents unnecessary re-computations of nested task IDs on every event append during live agent turns.Bug fixes
Git interaction state (
useFixWithAgent.ts): ResetisSubmittingflag when PR creation is cancelled, preventing the submit button from remaining locked.Session model preservation (related commits): Fixed an issue where the model selection was lost on session retry.
Token display formatting (
billing): Added billions unit formatting for large token counts.Changes in dependencies
AcpMessagetype import inagentChatService.tsfor message batching.How did you test this?
The commits reference existing test coverage and targeted fixes validated against their respective feature areas.
Created with PostHog Code