Repository navigation
perf(ui): keep chat renders independent of history length - #162035
Conversation
Draft-presence notifications republished empty outbox arrays, invalidating transcript items on the first keystroke. Stream paints also repeated history scans for participants, activity ownership, and gallery membership. Keep empty queues stable at their publisher. Cache derived facts by immutable inputs and a full-build generation while preserving stream-slot replacement. Share session input ordering across visible and unfiltered projections; keep reply navigation on the visible cache's stabilized disclosure keys. Reuse structural work-group metadata and memoize recovery and voice indexes. Source projection microbenchmark, median of seven 300-render bursts: - 534 messages: unchanged 51.72 -> 3.07 ms; streaming 93.74 -> 12.08 ms. - 3000 messages: unchanged 268.86 -> 7.45 ms; streaming 474.68 -> 14.49 ms. The 3000-message regression observes no retained-message reads or full builds on unchanged and stream-only renders. The production perf rig remains with the lead. Validation: 586 unit/browser tests across 33 files with one worker; 89 E2E cases across 15 files plus 32 final navigation/gallery cases; pnpm tsgo:ui; node scripts/check-changed.mjs.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 2:37 PM ET / 18:37 UTC (Revision 2). ClawSweeper reviewWhat this changesThe Control UI caches derived chat transcript data and preserves empty outbox identity so typing, streaming, and scrolling do less work in long conversations. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still repeats transcript work on warm renders, while the merged history-paging optimization addresses a different bottleneck. The pinned patch has no actionable finding from this review. Priority: P2 Review scores
Verification
How this fits togetherThe Control UI receives chat history and live updates from the Gateway, alongside browser draft and outbox state. Its chat projection turns those inputs into transcript rows, activity indicators, and media galleries for display. flowchart LR
A[Gateway chat history] --> C[Chat item cache]
B[Live updates and draft] --> C
C --> D[Transcript projections]
D --> E[Activity and video views]
D --> F[Rendered chat rows]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +172, Tests +433. Total +605 across 13 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one chat projection owner with explicit invalidation for structural changes, replaced messages, session changes, and live stream text, while preserving ordering and visible transcript behavior. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source shows the repeated history-dependent derivations, and the PR describes a concrete long-chat browser-bundle benchmark; I did not rerun it. Is this the best way to solve the issue? Yes. The patch addresses the repeated work at the outbox and transcript projection owners, with focused checks for cache invalidation and visible behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 112df95f5ee6. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
…every render (#162092) Pane renders repeatedly normalized both operands for every roster comparison, and abortability could scan the roster twice. Every stream delta also filtered the complete transcript to find persisted assistant messages for the active run. Bound the pure session-key memo to 4,096 inputs, precompute the fixed default main alias, and preserve false equivalence for blank keys. Share one roster pass with one normalized target. Cache persisted assistant filtering by immutable history-array identity and the latest run, using weak retention; keep all stream-dependent reconciliation live. This builds on immutable message replacement in #160215 and identity-keyed derivations in #162035. Microbenchmarks against a58e5ba, Node v24.21.0, median of seven warm samples after a first burst: - hasAbortableSessionRun, 1,500 rows x 100 calls: 38.083 -> 3.471 ms. - reconcilePersistedAssistantStream, 3,000 messages x 300 deltas: 44.310 -> 0.309 ms. First-burst times were 44.558 -> 4.302 ms and 49.742 -> 3.432 ms. No production perf rig was used. Protect bounded memo reuse, blank/opaque-key semantics, single-pass roster checks, and history-cache invalidation on run/array changes without test-only production hooks or timers. Control UI behavior remains unchanged.
…62035) Draft-presence notifications republished empty outbox arrays, invalidating transcript items on the first keystroke. Stream paints also repeated history scans for participants, activity ownership, and gallery membership. Keep empty queues stable at their publisher. Cache derived facts by immutable inputs and a full-build generation while preserving stream-slot replacement. Share session input ordering across visible and unfiltered projections; keep reply navigation on the visible cache's stabilized disclosure keys. Reuse structural work-group metadata and memoize recovery and voice indexes. Source projection microbenchmark, median of seven 300-render bursts: - 534 messages: unchanged 51.72 -> 3.07 ms; streaming 93.74 -> 12.08 ms. - 3000 messages: unchanged 268.86 -> 7.45 ms; streaming 474.68 -> 14.49 ms. The 3000-message regression observes no retained-message reads or full builds on unchanged and stream-only renders. The production perf rig remains with the lead. Validation: 586 unit/browser tests across 33 files with one worker; 89 E2E cases across 15 files plus 32 final navigation/gallery cases; pnpm tsgo:ui; node scripts/check-changed.mjs.
…every render (openclaw#162092) Pane renders repeatedly normalized both operands for every roster comparison, and abortability could scan the roster twice. Every stream delta also filtered the complete transcript to find persisted assistant messages for the active run. Bound the pure session-key memo to 4,096 inputs, precompute the fixed default main alias, and preserve false equivalence for blank keys. Share one roster pass with one normalized target. Cache persisted assistant filtering by immutable history-array identity and the latest run, using weak retention; keep all stream-dependent reconciliation live. This builds on immutable message replacement in openclaw#160215 and identity-keyed derivations in openclaw#162035. Microbenchmarks against af6e033, Node v24.21.0, median of seven warm samples after a first burst: - hasAbortableSessionRun, 1,500 rows x 100 calls: 38.083 -> 3.471 ms. - reconcilePersistedAssistantStream, 3,000 messages x 300 deltas: 44.310 -> 0.309 ms. First-burst times were 44.558 -> 4.302 ms and 49.742 -> 3.432 ms. No production perf rig was used. Protect bounded memo reuse, blank/opaque-key semantics, single-pass roster checks, and history-cache invalidation on run/array changes without test-only production hooks or timers. Control UI behavior remains unchanged.
Related: #160215
What Problem This Solves
Every chat pane render — each streaming delta, keystroke-driven update or scroll-driven render — re-derived several facts by scanning the entire loaded history: whether other people's sender names must be shown (a scan over every message that never short-circuits in a solo chat), which group owns the active run's activity (
findLastwith nested per-message activity reads), the turn video-gallery membership, forwarded-author detection, browser-preview rows and expansion pruning. Typing also triggered a full chat-item rebuild on the first character of a draft because the outbox owner published a fresh empty queue array. The cost grew linearly with history: at ~3,000 messages a render spent ~0.9 ms in projection even with no chat-item rebuild.User Impact
Streaming, typing and scrolling in long conversations no longer get slower as the history grows; no visible change. No configuration changes, migrations, or user action are required. Cold-session builds still derive the full history.
Why This Change Was Made
The outbox owner keeps the existing empty queue array when nothing changed. The chat-items cache records a structural generation on every full rebuild (not on the existing single-slot stream replacement) and keeps separate visible/unfiltered projections that share one input-order ledger. History-wide derivations are memoized next to their consumers, keyed by that generation or by message/pending-input identity (valid since #160215 made message replacement immutable): sender names/people, active-run activity group, video membership (live stream entry applied separately), forwarded authors, browser previews, expansion pruning, voice reconciliation.
Evidence
Synthetic benchmark, median ms per 300 projections: unchanged render 534 msgs 51.7 → 3.1, 3,000 msgs 268.9 → 7.5; stream-only delta 534 msgs 93.7 → 12.1, 3,000 msgs 474.7 → 14.5. After warm-up the 3,000-message regression records zero full builds and zero retained-message reads.
Production-bundle rig (mocked Gateway, source-mapped CPU profile,
projectChatTranscriptinclusive time; default = 534-message transcripts, ~5× = 2,934 messages / 1,500 sessions): streaming 300 deltas 101 → 44.5 ms (default), 354 → 74 ms (~5×); typing run 14.5 → 2.3 ms, 67 → 5.0 ms; scroll 8.9 → 0.6 ms, 36.6 → 3.1 ms; 4 session switches 82 → 88 ms (default, cold-session builds unchanged), 235 → 179 ms (~5×).Tests: 586 unit tests (33 files, one worker incl. neighbors), 89 + 32 e2e cases (streaming, search, shared/multi-person sessions, video gallery, activity/progress, composer typing, navigation),
pnpm tsgo:ui,check-changed; regressions cover keystroke no-rebuild, per-delta no history rescans, and invalidation when a replaced message changes sender names, activity grouping or video membership.Those benchmark and broad validation results were recorded before landing. Lead source review verified that chat message arrays are replaced immutably, and the independent Codex autoreview was scoped-clean at P2.
The branch was rebased onto
452758a4274aonly because of a conflict with main. Resolution retained main's sharedchatItemGroupsreader and this change's activity projection owner; range-diff shows only import-context adaptation.Fresh post-rebase test cost:
pnpm test ui/src/pages/chat/chat-pane-projection-scale.test.ts ui/src/pages/chat/components/chat-transcript-projection-scale.test.ts ui/src/pages/chat/components/chat-turn-video-gallery.test.ts --maxWorkers=1passed all 10 tests in 3 files; 22.55 seconds wall time (Vitest: 19.05 seconds; test bodies: ~0.57 seconds) on macOS. These are deterministic regression checks, without performance thresholds tied to machine speed.Post-rebase neighboring coverage also passed: 138 tests in 7 files for transcript input order, message indexing, reply navigation, recovery, voice reconciliation, invalidation, and rendering (42.46 seconds across the two routed Vitest shards). Total fresh proof: 148 tests in 10 files. All eight test type graphs, formatting, catalog validation, changed-file lint, and styles passed. The post-rebase changed-check run stopped at UI production typechecking on an inherited unused import:
src/gateway/server-cron.ts:113,reconcileCronExitWatchers(TS6133). That file is byte-identical to this branch's base; main has already removed the orphaned import ind5e602f0bcf8. This PR does not modify Gateway code. The remaining coercion and dead-export guards also passed separately.CI attempt 1 for
e04a66ed22d5db31eecb98c38c4e4dd30fb895d6: https://github.com/openclaw/openclaw/actions/runs/36757320474. All three UI unit shards, all nine UI E2E shards, both real-Gateway UI shards, Control UI performance, security-fast, and all other selected independent lanes passed. No lane was cancelled. Onlycheck-lint-core-1andcheck-prod-typesfailed, both on the inheritedreconcileCronExitWatchersimport described above;openclaw/ci-gateconsequently failed. Each failed job log was fetched once. No CI rerun has been requested.Updated the branch once through GitHub to incorporate the existing main-side repair
d5e602f0bcf8, without a local rebase or changes to the reviewed chat fix. The updated headfcd376cdd83210b1655c67b2aa6b56df05076435passed CI: https://github.com/openclaw/openclaw/actions/runs/36759177974 (41 jobs passed, 20 intentionally skipped, none failed or cancelled). ClawSweeper also reviewed this exact head and reported no actionable findings. Squash auto-merge completed asd53b32bb96a2ba6adbc4cb1d736f9d1433bb78b5, verified onorigin/main. There was one GitHub branch update and no CI rerun request.