Repository navigation
perf(ui): reduce idle CPU for offscreen sessions - #193998
Conversation
Suspend elapsed-time subscriptions using the existing sidebar visibility owner and release offscreen status-animation layers. Visible rows catch up immediately when returned to view. Extend the engines audit with native 30-second idle and hidden-tab evidence.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dee27ca6ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const seconds = [...read.matchAll(/(\d+)\s*([hms])/gu)].reduce( | ||
| (total, match) => | ||
| total + Number(match[1]) * (match[2] === "h" ? 3600 : match[2] === "m" ? 60 : 1), | ||
| 0, | ||
| ); |
There was a problem hiding this comment.
Make clock recovery checks locale-aware
When the engines harness runs a clock scenario with a non-English configuration such as locale:zh-CN, this parser rejects correctly advancing clocks. ElapsedTime formats units through the locale-aware Intl.NumberFormat in ui/src/lib/format.ts, so a valid label such as 35秒 produces zero parsed seconds here and eventually throws Clock did not catch up. The harness applies configuration.locale after scenario.settings, so the scenario's English setting does not prevent this. Compare against locale-aware expected labels, including the allowed tick tolerance, so localized runs do not report false failures.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
* perf(ui): stop offscreen sidebar clock work Suspend elapsed-time subscriptions using the existing sidebar visibility owner and release offscreen status-animation layers. Visible rows catch up immediately when returned to view. Extend the engines audit with native 30-second idle and hidden-tab evidence. * test(ui): measure scrolling running sidebar clocks * test(ui): keep clock scroll proof within running tree * refactor(ui): inline elapsed clock inputs * fix(ui): remove retired elapsed copy baseline * test(ui): share elapsed clock suspension coverage
What Problem This Solves
Expanded running-session trees consume CPU while idle because offscreen clocks update and status animations retain compositor layers.
User Impact
Visible clocks stay correct, including immediately after scrolling or returning to the tab. A 200-clock tree uses 12.5–15.9% less Chromium main-thread CPU. Visible geometry and animation stay the same; offscreen rings restart their phase on return. The measured WebKit wheel/resize flow is 4.0% slower in median application time, within the 5% band; its extra layout work is disclosed below.
Why This Change Was Made
Reuse the existing row-visibility owner to suspend offscreen elapsed clocks. Stop offscreen animations entirely: pausing retained transforms and promoted overlapping labels. Top-level rows are already windowed, so this needs no additional virtualizer, polling owner, cache, or dependency. The unreachable completed-duration branch is removed because the non-snoozed trail predicate requires an active child run.
The existing engines harness now covers 30-second connected idle intervals, native hidden Chromium windows, timer/rAF/observer counts, layer diagnostics, and clock recovery. Native wheel proof uses its application-time clock, with correctness checks after measurement. Upstream configuration and mutation-audit modes are preserved.
Related: #193807.
Evidence
Production HTTP and bundles, a connected synthetic Gateway, headless Chromium 156.0.8078.4 and WebKit 27.2, 1440×1000. No live Gateway/provider latency claim. Every idle interval is 30 seconds. Twenty rotated base/head/base comparisons at each Chromium rate and in WebKit; host load recorded. Chromium acceptance uses untraced renderer-thread CPU, not V8-profiled timings. WebKit reports instrumented elapsed work; its categories overlap and are not summed.
The native diagnostic retains 201 rows/200 clocks but cuts layers 410→69, overlap promotions 402→61, and retained-layer paint counter increments 151.83→28.30 per second (A/A 151.58). These are layer counter increments, not whole-page frames. The shared timer still fires for visible clocks; the patch removes work per tick. Counter/layer rates use their own endpoint spans, including passive profiler draining.
Native wheel input and resize: 20 Chromium comparisons and 30 WebKit comparisons, including ten additional WebKit pairs declared after a borderline initial median. All four wheel events and post-measurement first/last clock checks pass. Application time is first trusted input to last observed DOM commit, including intermediate driver waits; it is not paint latency.
Chromium's median is flat (+0.08%); WebKit's median/p95 move +4.0%/+3.9%, within the 5% flow band. There is a real internal cost when rows return: the earlier programmatic scroll diagnostic adds 2.74 ms Chromium layout and 6.17 ms WebKit layout per four-scroll/resize batch. Native-wheel WebKit layout likewise rises 21.82→30.48 ms, while script falls 115.58→87.45 ms and style falls 232.57→182.62 ms. This is an explicit transition-work tradeoff, not a claim that every subphase improves. Copied-bundle ablations separate clock catch-up from SVG animation reactivation; the combined candidate has the strongest idle result.
Hidden-tab verdict and route census
Hidden tabs stop rendering work but are not fully CPU-idle. Twenty accepted hidden comparisons give CPU median 899.26→893.69 ms/min (A/A 899.70), with zero style/layout work, rAF, or observer callbacks. P95 is 950.19→972.54 (A/A 966.04): no demonstrated hidden CPU improvement. Every native reveal and clock catch-up check passes. WebKit lacks a supported native headless hide path; no hidden-WebKit claim.
The one-second Gateway health timer remains. A corrected copied-bundle diagnostic reduces interval callbacks 30→1 in 30 seconds but CPU is 867.31→875.20 ms/min, with head control 904.91. That diagnostic gives no evidence to change Gateway liveness policy. The initial extra ablation slot was invalid because unchanged precompressed assets were served; it is excluded from causal claims. Corrected JavaScript/Brotli/gzip representations were verified.
Single-cell diagnostics cover New Session, Chat, Sessions, Activity, Usage, and Profile, realistic/large fixtures, visible/hidden Chromium at 1×/6× and visible WebKit. All 120 accepted route cells stay connected and retain visibility. Candidate instrumented Chromium CPU spans 91–123 ms/min visible and 388–707 hidden at 1×; 239–446 visible and 736–1,270 hidden at 6×. These are census observations, not statistical improvement claims.
Two complete target triples were replaced after physical display sleep changed native visibility; the original failures remain recorded. One complete Usage 6× pair was replaced after a fixture refresh-ready setup timeout before idle collection. Replacement provenance and all accepted cells were independently validated. The native-wheel smoke also exposed WebKit's per-event pixel rounding; its wait now accounts for that rounding. No failed setup is counted as a product timing result.
Validation and size
Final hash-normalized gzip comparison (base
8298d434d93, head5778c1d9b2b):Actual served startup gzip is 90,657→90,662 B JS and 36,823→36,825 B CSS. Chat and total CSS already exceed their absolute caps on the base; their +63 B/+3 B changes pass the strict base-relative 64-byte allowance. No cap or baseline changed. The first Chat comparison exceeded that allowance by 3 B; inlining two single-use elapsed-clock expressions resolved it, with all five regression tests still passing.
UI production LOC: 4,073→4,085 (+12). Benchmark: 1,415→1,849 (+434). Regression file: 81→81 (0). Raw-copy baseline: 432→425 (−7). Total touched paths: 6,001→6,440 (+439) against merged main. No new UI effects, DOM queries, direct listeners, manual cleanup, or owner APIs.
The first full CI run (
42174897038) passed all UI unit, seven UI E2E, both real-Gateway, performance, format and code-lint checks. Its two non-aggregate failures had one PR-caused source: deleting the unreachable0msbranch left its raw-copy baseline entry. The canonicalpnpm ui:i18n:baselineremoves exactly that entry;pnpm ui:i18n:verifyand an independent review pass. No runtime or build-input changes in this correction; measurements remain at runtime-identical5778c1d9b2b. The next run (42176519009) passed i18n but failed the test-line ratchet on an already-over-limit merge base and three E2E cases (prompt recall, scoped quota identity, sidebar involvement). The clock regression now shares the existing fixed-end/paused suspension table and standard Solid cleanup, preserving all assertions with zero added test lines and no allocation. All five cases pass; the paused case still fails on original source. The exact-base Testbox attempt queued and was stopped without executing tests. Those E2E failures remain unattributed; no inherited exception or root-cause fix is claimed. Fullci:fullrun 42178093186 now passes on current reviewed headdee27ca6eee4, including all UI unit, UI E2E, real-Gateway, i18n and baseline gates.Reproduce
Build base and head, then use
scripts/bench-control-ui-engines.tswith--bundle-dir <base> --compare-bundle-dir <head> --control-bundle-dir <base> --viewport desktop. Target:--steps idle-sidebar-clock-visible --engines chromium --cpu-only --pairs 20, also with--cpu-throttle 6; WebKit uses--trace. Hidden target:idle-sidebar-clock-hidden. Transition:sidebar-running-clock-scroll-resize --engines chromium,webkit --trace --pairs 20. Native attribution uses--native-auditseparately from timing. Route IDs areidle-{new,chat,sessions,activity,usage,profile}-{realistic,large}-{visible,hidden}.Visual proof
Before (synthetic running-session tree):
After (same visible layout; offscreen work suspended):