Repository navigation
perf(website): split the two long tasks of a cold chat open - #37706
Conversation
|
Before and after, a cold open of recorded from 1a4bb63 (right) and The page looks the same on both sides, which is the point: nothing the user sees moves. What differs is the longest main-thread task of the open, printed above each side for that take (151 ms and 109 ms with the recorder attached; 151 ms and 94.5 ms in the unattended paired runs in the description). Paired runs, longest task, ms:
Every counted open rendered 15 transcript rows and 28 session rows, read from the DOM. |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: both long tasks are split at their real seams, the deferred open is guarded against a re-run, a user pick and an unmount, and the change can be reverted cleanly. Notes
[DESIGN-REVIEWED] a21683a Description read[DESCRIPTION-READ] 4b14190d8d62fa4e616cf99911a298453f860205dd97784f8d1b5e5bcbb56f96 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: both timing changes rest on a paired measurement, and the one new helper has a single direct consumer. Not checked: Safari and Firefox use the timer fallback, and that path is unmeasured. What this change shipsInventory (5 items) — 5 justifiedIntent: shorten the longest main-thread task of a cold
[FIRST-PRINCIPLES-REVIEWED] a21683a Description read[DESCRIPTION-READ] ed5d3a4b428cbfc1f912b2c1073f9108265fcbf743893ad1bb809c3e3f05568e That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff only changes when work runs on a cold chat open. It adds or changes no control, label, string or visible state. [UX-REVIEWED] a21683a Description read[DESCRIPTION-READ] 22f53f8cbf737571245c2d1cf8398d52b9d8d77d702bbf772deec056c39e2d29 That sha256 names everything this verdict read: the PR description, plus the 4 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
Correction to this PR's description (no code change, head is still 1a4bb63). The first version said the five history tests "exposed" a second What I had: with
Both writes update one router state, and React commits pending transitions on one state together, so the earlier write never commits alone under a later one. The harness's So the helper change in |
1a4bb63 to
41290d1
Compare
|
Red check on 1a4bb63, read from the job log: |
|
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own. Approve. The deferred An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
Opening the dashboard on /chat?sid=<key> ran two long main-thread tasks. The longest was the one the session list arrived in: it rendered the sidebar, and the effect that opens the URL's session ran in the same task and mounted the transcript too. The second was the app's first render, run synchronously. The URL open waits one turn of the main thread once it finds its session in the list (website/src/lib/yieldToMain.ts: scheduler.yield(), or a zero-delay timer where the browser has none). While it waits the link stays armed exactly as it was before the list arrived. The turn opens only what a run of the effect that passed every guard left for it, so a session picked meanwhile, a re-run or an unmount cancels it. main.tsx hands the first render to React as a transition, so it is rendered in slices. Three tests change with the timing and keep their invariant. The history tests in ChatPage.backBeforePushCommits wait for the location the router committed, not for the address bar, before they start: the open's slug replace is issued outside the mount's act. One fake-timer test in ChatPage.sid advances its clock inside act.
41290d1 to
a21683a
Compare
|
Conflict cleared in a21683a. #37584 merged (fa4e40d) and added an import above the React import in |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On this head the review traced every way the deferred ?sid= open can end: a re-run during the wait, a user pick, a disconnect, the list dropping the session, unmount, StrictMode double mount and embed mode. Each one holds, and the existing guards (URL sync hold, auto-select, mount refetch) behave as they do on main. It also checked that startTransition around the first render leaves the boot-failure panel alone, that the new tests use fake timers and fail when the deferral is reverted, and that the two edits to existing tests keep their assertions. Done well: paired, interleaved measurements with an A/A control, and the body says plainly what was not measured.
Optional:
useChatPageSessionController.ts:637and:652: deleting the'taken'branch or the store re-read at the turn fails no test. A disconnect-then-reconnect case and a pick dispatched outsideactwould pin them.useChatPageSessionController.ts:641: the comment says only the cold open waits a turn. A warm in-app navigation to/chat?sid=Xalso waits one turn. That is harmless, but the comment could say so.ChatPage.backBeforePushCommits.test.tsx:180: the reason for the stricter precondition is written down only in the PR body. One test using the realBrowserRouterthat asserts a single pushState would pin it.

Problem / Motivation
Goal: Opening the dashboard on a chat blocks input for less time: the longest main-thread task of the open gets shorter, and the transcript appears no later.
A cold open of
/chat?sid=<key>runs two long main-thread tasks. The longest, about 150 ms, is the task the session list arrives in: it renders the sidebar, and the effect that opens the URL's session runs in the same task and mounts the transcript too. The second, about 115 ms, is the app's first render, run synchronously.Why it matters
A click or a key press that lands during a long task waits until the task ends. The dashboard's own target for this page is no task over 100 ms.
Not a goal
What changed (motivation → approach → change)
The two long tasks are each two pieces of work in one task. Each piece is given a task of its own.
website/src/pages/chat/useChatPageSessionController.ts: once the effect that opens?sid=finds its session in the list, it waits one turn of the main thread and then opens. The sidebar's render and the transcript's mount are separate tasksyieldToMain()website/src/lib/yieldToMain.ts:scheduler.yield(), which resumes ahead of other queued tasks; a zero-delay timer in a browser without itwebsite/src/main.tsx:startTransition(() => root.render(...)). React renders the app's first render in slices and yields between themWhile the open waits, nothing differs from the wait for the session list: the link stays armed, the URL is not rewritten, and the "session not found" timer keeps its meaning. The turn opens only what a run of the effect that passed every guard left for it. A session the user picks meanwhile, a re-run that fails a guard, or an unmount takes that away, and the store is read once more at the turn so a pick that has not rendered yet wins too. After the first open the effect opens at once, as on
main.Measurements
All numbers are mine, from one shared Linux host. A node server on 127.0.0.1 serves the built dashboard and answers
/apifromscripts/lib/stub-dashboard-api.mjswithscripts/lib/perf-fixture.mjs(222 sessions, the 100-row chat): no gateway and no model are involved.chrome-headless-shell(Chromium 145), no DevTools client and no CPU throttling, opens/chat?sid=perf-longcold with a fresh profile. Every counted run rendered the target content, read from the DOM: 15 transcript rows, 28 session rows, the transcript scrolled to its end. Arms interleave in each round with rotating order, and a pair counts only when both start loads are under 15 and within 2 of each other.Two runs of 10 rounds, load 6.5-14.9, 19 pairs.
mainis d470c46; "main again" is the same build as a second arm.mainit is in 0 of 40 (range 143-210).mainshows against itself, so this run does not show the open getting slower. The transcript's +16 ms is 1.4% of the open.With 40 ms added to every response, on this revision's build against
main@ 4dec84c (10 rounds, load 3.1-7.5, 10 pairs): the longest task goes from 142 to 92 ms (−52; A/A −1) and is at or under 100 ms in 7 of 10 opens. The transcript is at +6 ms (A/A +3), FCP at +10 ms (A/A −12), session rows at −74 ms (A/A −8).The loopback table's build is this revision's code before two comment edits and one added test. Not measured: a real gateway, Safari and Firefox (neither has
scheduler.yield()in every version, so they take the timer), a phone, a throttled CPU.Backwards compatibility
Compatible. The session opens one main-thread turn later than on
main; what opens, and every case in which the link is abandoned, is the same. Checked in Chromium on both builds: after the openhistory.lengthis the same, a session switch adds one entry, and Back and Forward land on the sessions they name.In a hidden tab of a browser without
scheduler.yield(), timers run about once a second, so the session can open up to a second later there.Removes nothing.
Tests
website/src/lib/yieldToMain.test.ts(3 tests, new):scheduler.yieldis used where it exists; the fallback settles in a later task and not as a microtask; aschedulerwithoutyieldtakes the fallback.website/src/test/ChatPage.sidOpenTurn.test.tsx(3 tests, new; a file of its own becauseChatPage.sid.test.tsxis at the 2,000-line cap): the URL session is not open when mount returns with the list present, the URL is untouched meanwhile, and it opens after one timer turn; a session picked during that turn wins and the URL session never comes on screen; a page that unmounts during that turn opens nothing. Withmain's controller the first and third fail.website/src/test/main.firstRender.test.ts(2 tests, new):main.tsxrenders the root once, insidestartTransition. A pin on the source, like the file's other pins: the module boots the app as it is imported.website/src/test/ChatPage.backBeforePushCommits.test.tsx(5 tests): the helperopenOriginis documented to "let its URL settle on a committed entry", and waited forwindow.location. The open's slug replace is issued outside the mount'sact, so the address bar shows it before the router commits it. The helper waits for the committed location, read in a layout effect. Each test's steps and assertions are unchanged.ChatPage.sid.test.tsx, "does not declare a session missing while the slot list has not arrived": the fake clock advances insideact, so React runs the update the turn schedules.hold()kept back the router update of the next write while the open's slug replace was already delivered and uncommitted, so the replace committed alone and URL sync wrote the switch a second time. The real router does not produce that order. Both writes update one router state, and React commits them together. Checked onmain's controller with the real<BrowserRouter>, React's own scheduling and no held history: a title change, then a switch 0 to 45 ms later while the replace's 30 ms transition renders, gives one commit and onepushStatein 12 of 12 timings. In Chromium on themainbuild, 11 timings from 0 to 60 ms: one entry each, and one Back returns. So the second push is a state only the harness reaches, and the helper stays out of it. URL sync is not changed.--sequence.shuffle(seeds 7919, 15838, 23757): 105 of 105 each time.test/test_flake_pattern_ratchet.pypasses.ChatPage, asid=URL, the controller ormain.tsx(643 files, 12,006 tests);scripts/run_scoped_tests.py --surface frontend;tsc -p tsconfig.app.json; eslint on the changed files;scripts/check_file_line_cap.py;jscpd; the repository's semgrep rules on the diff;i18n:check,lint:i18n,gen:ui --check, the theme-colour, phantom-class and restyle gates. All pass.Manual verification
In the built dashboard (stubbed API, headless Chromium 145),
mainand this branch side by side: opened/chat?sid=perf-long, waited for the transcript, picked another session in the sidebar, pressed Back, pressed Forward. Both builds gave the same URL and the samehistory.lengthat each step (2, 3, 3, 3), the same 15 transcript rows after the open, and no page error. Not verified: Safari, Firefox, a phone, a real gateway.Screenshots / video
Cold open of
/chat?sid=perf-long,mainon the left and this branch on the right, played at half speed. The page looks the same in both; the readout above each side is that take's own longest main-thread task and the time its transcript reached the DOM.recorded from 1a4bb63 (right), an earlier head of this branch with the same non-test code, and
main@ 4dec84c (left) · production builds · stubbed API and fixture, no gateway and no model · Playwright's recorder attached, which slows both sides: the takes read 151 ms and 109 ms where the unattended runs above read 151 ms and 94.5 ms. Four takes a side, alternating order, load 7.6-8.7; the GIF shows the take at each side's median.Related Issues
N/A. From the Chrome modern-web-guidance review of the dashboard (break-up-long-tasks, schedule-tasks-by-priority).
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.