Stop the shell render loop spinning when there is no display target

renderShell paints first and checks for a display target last, and the
stale-data repaint re-requests before that check. requestShellRender runs
`do { renderShell() } while (shellRenderQueued)`, and because a render is
already in progress the re-request just sets shellRenderQueued. So with no
display target the two feed each other: paint, report stale, re-queue, discard
the work, round again, with no yield and no backoff. SHELL_REFRESH_INTERVAL_MS
is 60 seconds, so the timer is not the driver.

Measured on a device with the glasses not presenting, from the app's own
frame-timings export: 40 of 40 recorded frames were render:shell
target=shell-overlay, every one discarded, mean 55 ms and median 53 ms apart,
so about 19 full renders a second all thrown away. Main thread state=Runnable
with utm=22599, and seven ANR records over three days, each "Input dispatching
timed out ... Waited 10001ms". Afterwards the same state produced 5 renders in
100 seconds, and the export showed a normal mixed workload again instead of
one loop crowding everything else out.

Hoisting the check above the paint fixes both halves at once: a frame with
nowhere to go costs nothing, and the stale-data re-request lives downstream of
the early return, so it can no longer feed the loop. The copy of the check that
used to sit after the paint is removed rather than left in place. Nothing
between the two points can change the result, and the compiler agrees: the
early return narrows this.phase, which made the "charging" comparison
unreachable (TS2367).

submitWindowFrame, the sibling path for in-process window frames, already
checks the display target before doing any work.

Not unit-tested. The change is in dashboard-controller.ts, which imports 56
modules, so a test there would mostly exercise mocks, and it is an ordering
defect rather than a predicate, so extracting a shouldPresent() helper would
pass both before and after. The shape that would work is pulling the render
gate and its stale-data retry into a small module taking the display target and
the stale flag and returning whether to paint and whether to re-request.
This commit is contained in:
JMO committed 2026-09-22 22:09:35 -07:00
1 parent be20b24985
commit df77b672f5
1 file changed
+18 -4
+18 -4
View File
@@ -2480,6 +2480,19 @@ class DashboardController {
this.pendingShellRenderCauseFrameId = 0;
const frameId = frameTimings.startFrame("render:shell", causeFrameId);
frameTimings.annotateFrame(frameId, shell.describeInputTarget());
// Nothing to send a frame to: stop here, BEFORE painting. This check used
// to run only after the paint, which made a no-display state a
// main-thread busy loop: paint (~55 ms) -> endRenderPass reports stale
// data -> requestShellRender re-queues (shellRenderQueued, since a render
// is in progress) -> the display check discards the work -> the do/while
// in requestShellRender goes straight round again. Measured on a device
// with the glasses not presenting: 40 of 40 frames discarded, ~19 a
// second, enough to starve input and ANR. Leaving early costs nothing and
// breaks the loop, because the re-request lives downstream of this point.
if (!this.display || this.phase === "charging") {
frameTimings.finishFrame(frameId, "discarded: shell render with no display target");
return;
}
const wantFreshData = this.nextShellRenderWantsFreshData;
this.nextShellRenderWantsFreshData = false;
if (wantFreshData) frameTimings.logFrame(frameId, "follow-up repaint that must not use cached data");
@@ -2498,11 +2511,12 @@ class DashboardController {
this.nextShellRenderWantsFreshData = true;
this.requestShellRender(frameId);
}
// The display-target check that used to live here now runs before the
// paint, at the top of this function. Nothing between the two can change
// it -- paintSurface is synchronous and there is no await in between -- so
// repeating it here is dead code, and the compiler agrees: the early
// return narrows this.phase, making the "charging" comparison impossible.
const display = this.display;
if (!display || this.phase === "charging") {
frameTimings.finishFrame(frameId, "discarded: shell render with no display target");
return;
}
// A shell overlay that dims what it covers (a context menu) must dim the
// window surfaces too, which live below the shell surface in the
// compositor: forward the factor before this frame composites.