Skip to content

perf(ui): keep chat renders independent of history length - #162035

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-ui-projection-scale
Sep 30, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-ui-projection-scale

Conversation

@steipete

@steipete steipete commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

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 (findLast with 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, projectChatTranscript inclusive 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 452758a4274a only because of a conflict with main. Resolution retained main's shared chatItemGroups reader 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=1 passed 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 in d5e602f0bcf8. 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. Only check-lint-core-1 and check-prod-types failed, both on the inherited reconcileCronExitWatchers import described above; openclaw/ci-gate consequently 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 head fcd376cdd83210b1655c67b2aa6b56df05076435 passed 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 as d53b32bb96a2ba6adbc4cb1d736f9d1433bb78b5, verified on origin/main. There was one GitHub branch update and no CI rerun request.

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.
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete enabled auto-merge (squash) September 30, 2026 18:16
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 30, 2026
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 2:37 PM ET / 18:37 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: fcd376cdd83210b1655c67b2aa6b56df05076435

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused invalidation coverage and quantified browser-bundle behavior proof, though the multi-cache change warrants normal merge review.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed owner is the Control UI chat projection. The PR reports before/after projection timings from the production browser bundle driven by a mocked Gateway through long-chat streaming, typing, and scrolling scenarios, with improved after-fix results; focused tests supplement that runtime evidence. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed owner is the Control UI chat projection. The PR reports before/after projection timings from the production browser bundle driven by a mocked Gateway through long-chat streaming, typing, and scrolling scenarios, with improved after-fix results; focused tests supplement that runtime evidence. No stored-data contract changes.
Evidence reviewed 8 items Current-main behavior: At the pinned main revision, the transcript projection scans chat items for activity and derives browser previews from transcript items on render; the introduced patch replaces these paths with cached projections.
Introduced cache boundary: The chat-item owner advances a generation on structural rebuilds while retaining its stream-only update path; separate visible and unfiltered projections share the input-order ledger.
Transcript integration: The projection keys browser previews by work groups, expansion version, session, and tab state, and uses a separate unfiltered chat-item cache for video-gallery membership during search.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +172, Tests +433. Total +605 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 9 298 126 +172
Tests 4 434 1 +433
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 732 127 +605

Review metrics

Metric Value Why it matters
Production and test growth production +172 net lines; tests +433 net lines The production growth implements the stated cache and invalidation boundaries, while the tests exercise warm-render and behavior-preservation cases.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Long-chat responsiveness is a useful, bounded Control UI improvement without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed owner is the Control UI chat projection. The PR reports before/after projection timings from the production browser bundle driven by a mocked Gateway through long-chat streaming, typing, and scrolling scenarios, with improved after-fix results; focused tests supplement that runtime evidence. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed owner is the Control UI chat projection. The PR reports before/after projection timings from the production browser bundle driven by a mocked Gateway through long-chat streaming, typing, and scrolling scenarios, with improved after-fix results; focused tests supplement that runtime evidence. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-30T18:21:12.191Z sha e04a66e :: needs maintainer review before merge. :: none

@steipete
steipete merged commit d53b32b into main Sep 30, 2026
91 of 92 checks passed
@steipete
steipete deleted the steipete/perf-ui-projection-scale branch September 30, 2026 18:42
steipete added a commit that referenced this pull request Sep 30, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant