Repository navigation
perf(ui): avoid repeated work while streaming replies - #182993
Conversation
Keep live row and marker structure immutable between visibility changes, notify the page scroll owner on observed row-size changes, and avoid per-text scroll work. Preserve first-publication follow and locked-reader behavior. Extend streaming evidence with post-layout text visibility and fast-provider bursts.
# Conflicts: # ui/src/pages/chat/components/chat-transcript-projection-scale.test.ts
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: blocked before merge. What this changesThis PR separates live reply text from transcript structure and defers eligible Markdown formatting within a 50 ms window. Example: A reply grows from “A growing reply” to “A growing reply with more text”.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 4 items remain Keep this PR open for repair: the optimization is useful, but the patch introduces reader-position jumps and leaves a Markdown caller broken. Priority: P2 Decision needed
Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway stream updates enter the Control UI chat owners, which project transcript rows and navigation markers, reconcile Markdown DOM, and maintain viewport position. flowchart LR
A[Gateway stream updates] --> B[Chat state owner]
B --> C[Transcript structure]
B --> D[Live text projection]
C --> E[Rows and position rail]
D --> F[Markdown reconciler]
F --> G[Measured geometry and end anchor]
E --> G
Technical reviewBest possible solution: Retain the existing Markdown and transcript owners while preserving captured reader anchors, completing the lazy-parts cutover, and meeting the recorded performance acceptance. Do we have a high-confidence way to reproduce the issue? Current main eagerly prepares streaming Markdown and refreshes live-owner projections; source inspection establishes the repeated work, while exact-head CI independently records the introduced caller and scroll failures. Is this the best way to solve the issue? Separating live text from structural indexes fits the existing owners, but unconditional anchor recovery violates reader-position preservation and the lazy-parts contract must reach every consumer. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6c33f5ff5ee0. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +182, Tests +420, Docs +4, Other +27. Total +633 across 26 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 24, 2026, 7:11 PM ET / 23:11 UTC. |
Reconcile the existing end anchor after the measured range commits, retaining the frame fallback and reader ownership checks. Prove the first-paint gap at the real ResizeObserver boundary and target the latest non-space glyph in the visibility probe.
Merge current main while preserving its direct DOM Markdown content, lazy transcript rows, and media admission. Keep safe text previews and callable formatting preparation over the same canonical renderer. Retain both security corpora and the pre-paint anchor repair.
Replace obsolete DOMParser call counts with visible autolink timing and retain immediate text and completion coverage after prepared-DOM rendering.
|
Merged via squash auto-merge.
|
* perf(ui): decouple live text from transcript formatting and layout * perf(ui): follow measured content through the page scroll policy Keep live row and marker structure immutable between visibility changes, notify the page scroll owner on observed row-size changes, and avoid per-text scroll work. Preserve first-publication follow and locked-reader behavior. Extend streaming evidence with post-layout text visibility and fast-provider bursts. * test(ui): record streaming benchmark timeout diagnostics * perf(ui): let captured transcript anchors own content growth * perf(ui): preserve visible text during formatting catch-up * perf(ui): coalesce formatting with arriving stream text * perf(ui): coalesce streaming formatting before paint * perf(ui): coalesce only stream deltas that share a frame * perf(ui): keep stream following in the existing end anchor * perf(ui): bound streaming formatting to fifty milliseconds * refactor(ui): keep suppressed row measurement in its owner * perf(ui): keep inline syntax out of streaming previews * perf(ui): isolate startup labels from streamed text * fix(ui): preserve measured transcript scroll ownership * fix(ui): preserve measured streaming scroll ownership * refactor(ui): inline the transcript settled-position check * fix(ui): follow measured streaming growth before paint Reconcile the existing end anchor after the measured range commits, retaining the frame fallback and reader ownership checks. Prove the first-paint gap at the real ResizeObserver boundary and target the latest non-space glyph in the visibility probe. * test(ui): assert streaming formatting at the visible boundary Replace obsolete DOMParser call counts with visible autolink timing and retain immediate text and completion coverage after prepared-DOM rendering. * perf(ui): record approved streaming cadence baseline * test(ui): acknowledge the actual Talk provider handshake
What Problem This Solves
Streaming replies repeatedly redo Markdown and transcript work for text-only deltas, wasting browser CPU and leaving newly started paragraphs below the viewport for a frame.
User Impact
New text remains visible on the next frame while safe Markdown formatting catches up within a fixed 50 ms window. Reader scroll-up, syntax, media, replacement, and final rendering retain their existing behavior.
Why This Change Was Made
A narrow live-text source keeps text-only deltas out of structural transcript and position projections. Literal text appends through the existing Markdown island; syntax, block boundaries, and completion remain canonical. The old live overlay/index replacement machinery is removed. Measured row growth reconciles through the existing end-anchor owner before paint, retaining reader authority and cancellation checks.
This head incorporates current main's prepared-DOM renderer and lazy transcript rows. The two optimizations share one renderer. Whole changed-file LOC is production 8,953 → 9,191 (+238), tests/support 5,973 → 6,399 (+426), docs 470 → 474 (+4), config 5 → 5. Effects/listeners/queries/flush/owner API counts are unchanged.
The coordinator explicitly approved the CPU/bytes tradeoff under the newer allowance for a clean ≥5% CPU win and up to approximately 2 KB gzip growth. After main’s dormant-chat deferral landed, the only merge conflict was the startup baseline. Fresh same-host builds preserve that reduction: startup 272,577 → 272,544 B (−33 B), Chat 1,247,947 → 1,248,649 B (+702 B), New Session 761,622 → 761,641 B (+19 B). Chat is 54 B above the previously approved +648 B, within the 64 B build-variance allowance. Requests and CSS are unchanged. The official checker ratchets startup to the measured 272,544 B.
Evidence
Current head:
f6d1985f71a; current bundle base:9794c6abbb6. CPU and visual proof used production3f327131d31against8e7fedf560c. Eighteen of nineteen lane production UI files remain byte-identical; the remaining change is main’s annotation-editor lazy load inchat-view-frame.ts, outside the streaming path. The later test assertions, Talk fixture repair, and baseline updates do not change runtime behavior.1b1fb96d018; integrated production visibility probes below cover the final repair9794c6abbb6: one unlisted binary,scripts/generate-social-preview.mts: ffmpeg. No UI orphan is reported; the prior measured head passed.f6d1985f71a, including everyci:fullUI unit, E2E, browser-extension, and real-Gateway shardThe two Gateway type jobs in the prior CI run have the same sole diagnostic on the clean merge base:
src/gateway/server-methods/session-catalog.test-helpers.ts(122,5)TS2739 ({}lacksminProtocol,maxProtocol, andclient). Bothpnpm tsgo:coreand the Gateway-methods test typecheck reproduce it at8e7fedf560c. UI, extension, and UI test type leaves passed. That prior run also identified two cadence assertions counting DOMParser calls, obsolete after main’s prepared-DOM renderer; these now assert the visible autolink deadline, and all 43 streaming browser tests pass locally. Earlier real scroll/Markdown regressions were repaired; they are not classified as inherited.Performance acceptance
Each workload runs 20 serial interleaved base/A-A/head triplets on this Mac, using production bundles, 400 history messages, 645 deterministic deltas, and native typing. Standard: 30 deltas/s; burst: 150/s in groups of five. Renderer thread CPU, input latency, frame gaps, dropped-frame estimates, structural counters, final output, and host load are retained. The A/A candidate is an identical base bundle.
Burst measurement is complete. Across 20 base/A-A/head sets, renderer-thread script CPU median is 636.6 → 531.8 ms (−16.5%; paired median −17.9%), and its p95 is 1,057.1 → 946.9 ms. Median per-run p95 input latency is 19.54 → 18.05 ms; p95 frame gap stays 33.4 ms. Dropped-frame median is 53.5 → 55.5, with p95 76.75 → 76.1; the A/A median is 61.5, showing shared-host frame-count noise. Position-rail observations fall 207.5 → 145 per stream; pane renders stay at one on the head. Every run ends at bottom gap 0 with the same comment-normalized final HTML hash.
Standard streaming is also complete: renderer-thread script CPU median is 1,736.95 → 1,375.20 ms (−20.8%; paired median −20.45%), with p95 1,891.60 → 1,401.00 ms. Renderer task CPU falls 4,652.78 → 4,297.64 ms. Median per-run p95 typing latency is 20.91 → 20.14 ms, and p95 frame gap remains 33.4 ms. Dropped-frame median is 247.5 → 255 (A/A 259), with p95 319.05 → 315.6. Rail observations fall 535.5 → 317 (−40.8%). All runs again have bottom gap 0 and identical comment-normalized final HTML.
The head improves script CPU in 20/20 standard pairs and 18/20 burst pairs. Burst run 30 remains an outlier at 1,828 ms script CPU, 1,529 HTML parses, and 3.37M parsed characters; it represents extra browser work, not just scheduling delay. A/A has parser/CPU outliers too. Publications and row resize deliveries remain roughly unchanged; the reliable structural reduction is position-rail work.
Neither the ≤1.0 s standard target nor the 50% burst CPU target is reached. These remain goals, not landing gates. The A/A dropped-frame and latency spreads exceed the timing band on this shared host (load roughly 50–90), so wall/frame outliers are treated as noise; twenty interleaved renderer-thread CPU pairs show the gain, and structural rail work falls in both workloads. Acceptance uses the campaign's ≤5% median/p95 band and noisy-host A/A rule. Earlier timing results are superseded because merging main changed the Markdown renderer itself.
Bundle comparison
CSS bytes and requests are unchanged, including one startup CSS request. No new dependency or eager import was added by this lane.
Visual proof
Inspected synthetic fixtures only. The failed-check labels are fixture content. The before/after completion captures retain code highlighting and tables. The contact sheet shows base above head, at delta 162, delta 323, and completion. Full burst captures contain 335/214 frames; the standard filmstrip reaches Chromium's 450-frame capture limit, while the independent visibility probe covers the entire stream.
The first landing attempt stopped before dispatch because main’s lower startup baseline conflicted. No request or intent was retained. Main was merged; the lower baseline was preserved and measured afresh. Independent review of the merged candidate is clean through P2. UI typecheck and the fresh strict size check pass. Native review/preparation completed for the test-only Talk handshake repair at
f6d1985f71a. Full CI40158671607 passed and native auto-merge landed this head as1d0d6db702187d833f1c3e0cde8ac859cb33a1e4. CI40156938097 completed with that single E2E failure; it is repaired rather than classified as inherited, because the latest scheduled main shard passed.