diff --git a/robot-docs/web.md b/robot-docs/web.md index f05d4b67d..8e891ae68 100644 --- a/robot-docs/web.md +++ b/robot-docs/web.md @@ -271,6 +271,19 @@ The [HTTP API behavior guide](../docs/http-api-design.md) defines the browser client's ordering and recovery obligations. [OpenAPI](../docs/openapi.yaml) owns its wire shapes. +## Motion and streaming costs + +A busy session's face, [`LiveFace.svelte`](../web/src/lib/LiveFace.svelte), +steps on one shared clock in [`live.svelte.ts`](../web/src/lib/live.svelte.ts). +Every frame of its animation sits laid out in one grid cell, and a tick only +moves the colour to the next one. Changing the face's text instead lays out the +whole page and makes Chrome hit-test it again for hover; toggling visibility +skips the layout but rebuilds the compositor layers. Both cost the page a frame +of main-thread work twice a second for every streaming session in the rail. +Giving the face its own compositing layer does not help. The `animateFaces` +browser preference ("animate session faces") holds every face on its first frame +and stops the clock. + ## Terminals The browser's terminal views attach over the WebSocket route in diff --git a/web/src/lib/LiveFace.svelte b/web/src/lib/LiveFace.svelte index 82cfa7547..1e5b26594 100644 --- a/web/src/lib/LiveFace.svelte +++ b/web/src/lib/LiveFace.svelte @@ -2,10 +2,13 @@ import type { Session } from './api'; import { clock, liveFrames, liveMood } from './live.svelte'; import { hasFastAnimation } from './moods'; + import { prefs } from './prefs.svelte'; - // The face a busy session makes, animated for what it is doing now. The - // widest frame sits invisibly under the current one, so the face holds its - // width as it moves and nothing beside it shifts. + // The face a busy session makes, animated for what it is doing now. Every + // frame is laid out once in the same cell, so the face holds its width as it + // moves, and a tick only changes which one has a colour: no layout and no + // new layers, only a repaint of the face. Changing its text or visibility + // instead costs the whole page a layout or a relayering twice a second. let { session, label = false, @@ -15,7 +18,13 @@ session ? liveFrames(session.id, mood, session.fast) : [], ); - $effect(() => clock.use()); + const now = $derived( + prefs.animateFaces ? clock.tick % Math.max(set.length, 1) : 0, + ); + + $effect(() => { + if (prefs.animateFaces) return clock.use(); + }); {#if session} @@ -25,10 +34,11 @@ class="face kaomoji" class:speedy={session.fast && hasFastAnimation(mood)} > - {#each set as frame, index (index)}{frame}{/each} - {set[clock.tick % set.length]} {/if} @@ -48,17 +58,18 @@ display: inline-grid; font-weight: var(--weight-medium); } - .sizer, - .now { + .frame { grid-area: 1 / 1; + color: transparent; + user-select: none; + } + .frame.now { + color: inherit; + user-select: auto; } /* Padding reserves terminal cells; right alignment also anchors the runner with the proportional fallback fonts used by the browser. */ - .speedy .sizer, - .speedy .now { + .speedy .frame { text-align: right; } - .sizer { - visibility: hidden; - } diff --git a/web/src/lib/prefs.svelte.ts b/web/src/lib/prefs.svelte.ts index 5b938073b..d975000a1 100644 --- a/web/src/lib/prefs.svelte.ts +++ b/web/src/lib/prefs.svelte.ts @@ -132,6 +132,8 @@ interface Saved { wrapCode: boolean; /** Whether thinking, tools and mid-turn prose start folded. */ collapseTraces: boolean; + /** Whether a busy session's face animates rather than holding still. */ + animateFaces: boolean; palettes: Record; fonts: Fonts; text: Text; @@ -242,6 +244,7 @@ function load(): Saved { closeNotes: false, wrapCode: false, collapseTraces: false, + animateFaces: true, palettes: { ...DEFAULTS }, fonts: { ui: '', code: '' }, text: { ...TEXT_DEFAULTS }, @@ -268,6 +271,7 @@ function load(): Saved { closeNotes: saved.closeNotes === true, wrapCode: saved.wrapCode === true, collapseTraces: saved.collapseTraces === true, + animateFaces: saved.animateFaces !== false, palettes: { light: readPalette(saved.palettes?.light, 'light'), dark: readPalette(saved.palettes?.dark, 'dark'), @@ -318,6 +322,7 @@ class Prefs { closeNotes = $state(this.#saved.closeNotes); wrapCode = $state(this.#saved.wrapCode); collapseTraces = $state(this.#saved.collapseTraces); + animateFaces = $state(this.#saved.animateFaces); palettes = $state>(this.#saved.palettes); fonts = $state(this.#saved.fonts); text = $state(this.#saved.text); @@ -369,6 +374,7 @@ class Prefs { closeNotes: this.closeNotes, wrapCode: this.wrapCode, collapseTraces: this.collapseTraces, + animateFaces: this.animateFaces, palettes: this.palettes, fonts: this.fonts, text: this.text, diff --git a/web/src/lib/settings/BrowserSettings.svelte b/web/src/lib/settings/BrowserSettings.svelte index 35a9ee7a9..5ce37924a 100644 --- a/web/src/lib/settings/BrowserSettings.svelte +++ b/web/src/lib/settings/BrowserSettings.svelte @@ -531,6 +531,25 @@ > + +
+

motion

+ +
{/if} {#if section === 'layout'}