Repository navigation
perf(showcase-dashboard): memoize matrix cells + coalesce SSE deltas - #4502
Merged
Merged
Conversation
The matrix tab can freeze the browser on load and during update bursts because every PB SSE delta triggers a full re-render of all ~720 cells (18 integrations × ~40 features), and PocketBase fires the subscribe callback once per record — a probe finishing dozens of services or an initial-state replay produces N consecutive React commits. - ComposedCell: wrap in React.memo with a custom equality check that compares overlays/catalogCell refs, ctx scalars, and (when the liveStatus Map identity changes) only the 5 row keys this cell actually reads. Because upsertByKey preserves row identity for unchanged keys, deltas that don't touch a cell's slug/featureId short-circuit at the memo boundary. - useLiveStatus: buffer SSE callbacks into a per-key Map and flush via a single 16ms setTimeout. A burst of N deltas now produces 1 React commit instead of N. Last-write-wins per key. Buffer is cleared on teardown and on reconnect kickoff so post-reconnect initial fetches never land on top of stale buffered rows.
AlemTuzlak
requested review from
jpr5,
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
April 30, 2026 14:42
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📣 Social Copy GeneratorGenerate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.
|
AlemTuzlak
enabled auto-merge
April 30, 2026 14:58
3 of 5 tasks
jpr5
added a commit
that referenced
this pull request
Apr 30, 2026
…ges (#4504) ## Summary Follow-up to #4502. With matrix cells memoized and SSE deltas coalesced, the dashboard is much smoother — but the **initial dashboard load** still freezes for a few seconds because: 1. **Initial PB fetch is 10 sequential round-trips.** `fetchInitial` walks `getList(page=1, 200) → getList(page=2, 200) → …` up to 10 pages, each awaiting the previous. Network wall time stacks. 2. **First commit with real data is unavoidably a full-matrix re-render.** The empty-map → populated-map transition invalidates per-key memo checks on every cell — that's 720 cell renders in one synchronous React commit, blocking the main thread. ## Changes - **Parallelize the initial fetch.** Pull page 1 sequentially to learn `totalItems`, then fire pages 2..N concurrently via `Promise.all`. Wall time drops from `sum(rtt_per_page)` to roughly `max(rtt_per_page)` modulo network parallelism. PocketBase reads are independent so this is safe. - **`startTransition` around the initial `setRows(initial)`.** The first big commit is unavoidable, but marking it as a transition lets React 19 yield to user input mid-walk instead of blocking for the entire render. `setStatus` stays urgent so the "connecting → live" indicator still flips immediately. - **`startTransition` around the SSE flush.** Bursts that the 16ms coalescer can't fully absorb (large reconnect replays, simultaneous probe completions) still need to yield rather than block. ## Test plan - [x] `useLiveStatus.test.tsx` 15/15 pass with parallelized fetch (the mock handles arbitrary page numbers). - [x] `composed-cell.test.tsx` 9/10 pass (1 pre-existing failure, same as #4502). - [x] No new TypeScript errors in `useLiveStatus.ts`. - [ ] **Manual perf trace before/after on the live dashboard.** Expected: initial-load wall time drops sharply (sequential → parallel pages), and any remaining heavy commit no longer blocks the main thread (transition lets React yield). - [ ] **Functional sanity** — confirm rows still arrive correctly when pages return out of order, and the "connecting → live" status transition still fires before the heavy render.
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…opilotKit#4502) ## Summary The shell-dashboard matrix tab can spike CPU and freeze the browser on load and during update bursts. Two compounding causes: 1. **Every PB SSE delta forces a full grid re-render.** The matrix renders ~720 cells (18 integrations × ~40 features), and nothing in the cell tree was memoized — a single status row update propagated a new `ctx.liveStatus` Map identity through every cell, and identity-based React.memo couldn't help because the Map ref changed. 2. **PocketBase fires the subscribe callback once per record.** A probe finishing dozens of services, or the initial-state replay on reconnect, produced N consecutive `setRows` calls and N React commits across separate microtasks (auto-batching only catches synchronous bursts). ## Changes - **`ComposedCell`** wrapped in `React.memo` with a custom `arePropsEqual`. Compares `overlays`/`catalogCell` refs, ctx scalars, and — when the `liveStatus` Map identity changes — only the 5 row keys this cell actually reads (`health:slug`, `e2e:slug/feature`, `smoke:slug`, `d5:slug/feature`, `d6:slug/feature`). Because `upsertByKey` preserves row identity for unchanged keys, deltas that don't touch a cell's `slug/featureId` short-circuit at the memo boundary. - **`useLiveStatus`** buffers SSE callbacks into a per-key `Map<string, PendingOp>` and flushes via a single 16ms `setTimeout`. A burst of N deltas now produces 1 React commit instead of N. Last-write-wins per key. Buffer is cleared on effect teardown and on reconnect kickoff so post-reconnect initial fetches never land on top of stale buffered rows. ## Why these two together Throttling alone would still re-render every cell on each flush. Memoization alone would still get invalidated on every delta because each delta produces a new Map. Together: a burst of unrelated row updates → 1 React commit, and within that commit only cells whose specific rows changed actually re-render. ## What I have not changed - The three independent `useNowTick` 1s timers on the Ops tab. They only matter if the freeze reproduces on Ops, not Matrix; happy to consolidate as a follow-up if needed. - `OverlayColumnHeader` (rendered 18× in the header, calls `LevelStrip` which does 4 Map lookups each). Same memo treatment would apply if these still show up after this lands. - No virtualization. Should not be necessary if the memo + throttle combo works as expected. ## Test plan - [x] Existing unit tests in the touched files pass — `useLiveStatus.test.tsx` 15/15, `composed-cell.test.tsx` 9/10 (the 1 failure is a pre-existing test-vs-impl drift in the "renders 3 layers when all active — docs deduped by health" case, verified by stashing my changes and re-running). - [x] No new TypeScript errors in the touched files. - [ ] **Manual perf trace before/after on the live dashboard** — Chrome DevTools → Performance tab → record while loading the dashboard against a real PB feed. Expected: scripting time during initial load and during probe-finish bursts drops sharply. - [ ] **Functional sanity** — confirm cells still update on real status changes (e.g. trigger a probe and watch the matching cell flip tone within ~1 frame).
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…ges (CopilotKit#4504) ## Summary Follow-up to CopilotKit#4502. With matrix cells memoized and SSE deltas coalesced, the dashboard is much smoother — but the **initial dashboard load** still freezes for a few seconds because: 1. **Initial PB fetch is 10 sequential round-trips.** `fetchInitial` walks `getList(page=1, 200) → getList(page=2, 200) → …` up to 10 pages, each awaiting the previous. Network wall time stacks. 2. **First commit with real data is unavoidably a full-matrix re-render.** The empty-map → populated-map transition invalidates per-key memo checks on every cell — that's 720 cell renders in one synchronous React commit, blocking the main thread. ## Changes - **Parallelize the initial fetch.** Pull page 1 sequentially to learn `totalItems`, then fire pages 2..N concurrently via `Promise.all`. Wall time drops from `sum(rtt_per_page)` to roughly `max(rtt_per_page)` modulo network parallelism. PocketBase reads are independent so this is safe. - **`startTransition` around the initial `setRows(initial)`.** The first big commit is unavoidable, but marking it as a transition lets React 19 yield to user input mid-walk instead of blocking for the entire render. `setStatus` stays urgent so the "connecting → live" indicator still flips immediately. - **`startTransition` around the SSE flush.** Bursts that the 16ms coalescer can't fully absorb (large reconnect replays, simultaneous probe completions) still need to yield rather than block. ## Test plan - [x] `useLiveStatus.test.tsx` 15/15 pass with parallelized fetch (the mock handles arbitrary page numbers). - [x] `composed-cell.test.tsx` 9/10 pass (1 pre-existing failure, same as CopilotKit#4502). - [x] No new TypeScript errors in `useLiveStatus.ts`. - [ ] **Manual perf trace before/after on the live dashboard.** Expected: initial-load wall time drops sharply (sequential → parallel pages), and any remaining heavy commit no longer blocks the main thread (transition lets React yield). - [ ] **Functional sanity** — confirm rows still arrive correctly when pages return out of order, and the "connecting → live" status transition still fires before the heavy render.
This branch was successfully deployed
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.
Summary
The shell-dashboard matrix tab can spike CPU and freeze the browser on load and during update bursts. Two compounding causes:
ctx.liveStatusMap identity through every cell, and identity-based React.memo couldn't help because the Map ref changed.setRowscalls and N React commits across separate microtasks (auto-batching only catches synchronous bursts).Changes
ComposedCellwrapped inReact.memowith a customarePropsEqual. Comparesoverlays/catalogCellrefs, ctx scalars, and — when theliveStatusMap identity changes — only the 5 row keys this cell actually reads (health:slug,e2e:slug/feature,smoke:slug,d5:slug/feature,d6:slug/feature). BecauseupsertByKeypreserves row identity for unchanged keys, deltas that don't touch a cell'sslug/featureIdshort-circuit at the memo boundary.useLiveStatusbuffers SSE callbacks into a per-keyMap<string, PendingOp>and flushes via a single 16mssetTimeout. A burst of N deltas now produces 1 React commit instead of N. Last-write-wins per key. Buffer is cleared on effect teardown and on reconnect kickoff so post-reconnect initial fetches never land on top of stale buffered rows.Why these two together
Throttling alone would still re-render every cell on each flush. Memoization alone would still get invalidated on every delta because each delta produces a new Map. Together: a burst of unrelated row updates → 1 React commit, and within that commit only cells whose specific rows changed actually re-render.
What I have not changed
useNowTick1s timers on the Ops tab. They only matter if the freeze reproduces on Ops, not Matrix; happy to consolidate as a follow-up if needed.OverlayColumnHeader(rendered 18× in the header, callsLevelStripwhich does 4 Map lookups each). Same memo treatment would apply if these still show up after this lands.Test plan
useLiveStatus.test.tsx15/15,composed-cell.test.tsx9/10 (the 1 failure is a pre-existing test-vs-impl drift in the "renders 3 layers when all active — docs deduped by health" case, verified by stashing my changes and re-running).