Repository navigation
perf(web): stop re-rendering the page on every MCP message - #2931
Merged
Merged
Conversation
With the monitoring sidebar open the web load panel was capped at ~11 calls/s (~68 closed) because the browser main thread spent ~95% of a run re-rendering. Profiling found four per-message costs: - App subscribed to the message, fetch and stderr logs, and to the client's connection diagnostics (re-dispatched on every request and response), each rendering the whole page synchronously per event. useStoreSnapshot now takes an optional NotifyScheduler; the web client coalesces those four subscriptions to the animation frame. Only the notification is deferred: the hooks re-read the live store, so no entry is dropped or reordered. - Every Protocol/Network row re-rendered on every message. Rows are now memoized, with the parent's handlers passed through stable useLatestCallback stand-ins, and MessageLogState replaces an entry when it folds in a response instead of mutating it, so identity is a sound memo key. - Each row mounted its collapsed detail body (two read-only Ace editors for a Protocol entry) and a closed edit-and-replay Modal up front. Both now mount on first open (useOpenedOnce) and stay mounted. - The Protocol/Network correlation re-parsed every fetch body on every render; the parses are memoized per (immutable) entry. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the web monitoring rendering optimizations.
No open issues 🎉
What changed in this PR
Addresses #2928 by reducing per-message rendering work in the web monitoring UI, using optional scheduling in shared React hooks while leaving TUI behavior unchanged.
Changes:
- Coalesces log and connection-diagnostic notifications to animation frames while continuing to read live store data.
- Memoizes Protocol and Network rows, replaces updated message entries immutably, and delays detail mounting until first open.
- Caches transport-body parsing per entry and adds regression tests for scheduling, entry updates, callbacks, and lazy mounting.
| File | Description |
|---|---|
core/react/useStoreSnapshot.ts |
Supports optional coalesced notifications and cleanup. |
core/react/useStderrLog.ts |
Accepts an optional notification scheduler. |
core/react/useMessageLog.ts |
Adds scheduling and documents immutable entry updates. |
core/react/useInspectorClient.ts |
Allows connection diagnostics to use scheduled notifications. |
core/react/useFetchRequestLog.ts |
Accepts an optional notification scheduler. |
core/react/notifyScheduler.ts |
Adds notification coalescing and animation-frame scheduling. |
core/mcp/typedEventTarget.ts |
Updates commentary while preserving the revision-counter contract. |
core/mcp/state/messageLogState.ts |
Replaces updated entries instead of mutating them. |
clients/web/src/utils/correlateTransportErrors.ts |
Caches request-ID and response-error parsing per entry. |
clients/web/src/utils/correlateTransportErrors.test.ts |
Tests repeated scans and replacement-entry handling. |
clients/web/src/test/integration/mcp/inspectorClient-response-rejected.test.ts |
Re-reads entries after rejection annotations. |
clients/web/src/test/core/react/useStoreSnapshot.test.tsx |
Tests coalescing, cleanup, and live snapshot reads. |
clients/web/src/test/core/react/notifyScheduler.test.ts |
Tests scheduling, cancellation, and timer fallback. |
clients/web/src/test/core/mcp/state/messageLogState.test.ts |
Tests immutable updates and evicted-request handling. |
clients/web/src/hooks/useOpenedOnce.ts |
Adds a persistent first-open latch for lazy mounting. |
clients/web/src/hooks/useOpenedOnce.test.tsx |
Tests initial and subsequent open states. |
clients/web/src/hooks/useLatestCallback.ts |
Provides stable callbacks that invoke the latest handler. |
clients/web/src/hooks/useLatestCallback.test.tsx |
Tests callback identity and current-handler invocation. |
clients/web/src/hooks/useInspectorStores.ts |
Enables animation-frame scheduling for all three logs. |
clients/web/src/components/groups/ProtocolListPanel/ProtocolListPanel.tsx |
Memoizes Protocol rows with stable callbacks. |
clients/web/src/components/groups/ProtocolListPanel/ProtocolListPanel.test.tsx |
Tests fresh replay handlers and updated row content. |
clients/web/src/components/groups/ProtocolEntry/ProtocolEntry.tsx |
Defers detail and replay-modal mounting until first use. |
clients/web/src/components/groups/ProtocolEntry/ProtocolEntry.test.tsx |
Tests lazy mounting and adjusts detail assertions. |
clients/web/src/components/groups/NetworkStreamPanel/NetworkStreamPanel.tsx |
Memoizes Network rows and stabilizes reveal callbacks. |
clients/web/src/components/groups/NetworkStreamPanel/NetworkStreamPanel.test.tsx |
Tests invocation of the latest reveal callback. |
clients/web/src/components/groups/NetworkEntry/NetworkEntry.tsx |
Defers detail mounting until first expansion. |
clients/web/src/components/groups/NetworkEntry/NetworkEntry.test.tsx |
Tests first-open mounting and retention after collapse. |
clients/web/src/App.tsx |
Enables scheduled connection-diagnostic notifications. |
AGENTS.md |
Updates the historical mutation example without changing the rule. |
Review effort: Balanced
Member
Author
|
Copilot review loop closed: round 1 came back clean (no inline comments, no suppressed findings, "no open issues"), which is the stop condition. |
This was referenced Nov 5, 2026
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.
Closes #2928
Root cause
A CPU profile of a sidebar-open load run, plus a commit counter on React's devtools hook, turned up four per-message costs. The first is shared by both cases:
Appre-rendered synchronously on every log event.Appsubscribes to the message, fetch and stderr logs. Each log dispatches once per entry, anduseSyncExternalStorerenders synchronously on every notification. The client's connection diagnostics (connectionDiagnosticsChange) are re-dispatched on every request and every response, so eachtools/callrendered the whole page about four times. That was the closed-sidebar ceiling of ~68/s.Collapsekeeps its children in the tree. A compact Protocol row therefore mounted two read-only Ace editors and a closed edit-and-replayModalas soon as it appeared.JSON.parseover the whole fetch log once perApprender.Fix
useStoreSnapshottakes an optionalNotifyScheduler(core/react/notifyScheduler.ts). The web client passesanimationFrameSchedulerfor the three logs and for connection diagnostics, so any burst costs one render per frame. Only the signal is deferred: the hooks still re-read the live store, so no entry is dropped or reordered, and a render that happens sooner for another reason already sees the latest list. OtheruseInspectorClientvalues (status, capabilities, …) stay immediate. The TUI is unchanged because the parameter is optional.ProtocolEntryRowandNetworkEntryRoware wrapped inmemo. The parent's handlers are new functions on every render, so they now reach the rows throughuseLatestCallbackstand-ins. To make entry identity a sound memo key,MessageLogStatenow replaces an entry with an updated copy when it folds in a response, a rejection or a send failure, instead of mutating it.FetchRequestLogStatealready worked this way. TheAGENTS.mdandTypedEventTargetnotes that used the old mutation as their example are updated, and the revision-counter rule they state is unchanged.useOpenedOncegates the Protocol and Network detail bodies and the edit-and-replay modal. Once mounted they stay mounted, so collapsing still animates and an editor keeps its state.correlateTransportErrorsthe parses are memoized in aWeakMapkeyed by entry. Fetch entries are immutable, so a replaced entry is parsed fresh.Measurements
Method: the same throwaway Playwright script for both builds. It runs the prod web server (minified
vite build) and the composablemodern-httpconfig (echoover Streamable HTTP), then drives Tools →echo→ Load test at concurrency 5 with no rate limit, two repetitions each. Headless Chromium, 1280×900, same machine.origin/v2/main)React commits during a 4 s closed run fell from ~1,590, about four per call, to ~340, about one per frame.
Correctness. A fixed 200-request run with the sidebar open shows exactly 200
tools/call echorows, all answered and nonePending.What is left, and the load panel's hint
With the sidebar open the page is still about 10× slower than with it closed. A trivial-row experiment, with each Protocol row rendered as a single
Text, reached ~1,300/s open. That puts the remaining cost entirely in mounting and folding one real row: about 3 ms of Mantine per row, and the per-rowScrollAreaon the compact target is the largest piece (removing it alone took the 12 s figure from ~105 to ~178/s). Fixing that means virtualizing the lists or replacing the per-row scroller, which is new scope and is filed as a follow-up. The load panel's "close the sidebar to measure the server" hint is therefore still accurate and left as is.No visible UI change, so no screenshots.
🤖 Generated with Claude Code