routing: flowing wires and held dots move from a 15/s timer, not per-frame CSS animations
With several requests in flight (Claude Code's subagents, five at once), magpie on Windows sat at 20-30% of a core for as long as they ran (chenxiang, #5467). The gateway's own share is small: about 2.2 CPU-s per 56s of five streams on macOS (~4% of a core) and 4.0-5.2 on Windows (~8%), unchanged by this commit. Most of the rest was the Routing page in the webview, which Task Manager counts under magpie on Windows: each flowing wire's copy in .rt-flows animated its stroke-dashoffset, and each dot held at an account pulsed its opacity under a drop-shadow filter. Chromium draws both on the main thread every frame, and a flowing wire spans the whole stage. Both now move from one setInterval at 15 Hz (slowTick) that sets --rt-dash on the flows svg and --rt-held on the sky; the CSS reads them. The timer runs only while a wire flows or a dot is held, the page is in sight and motion is on, and clears both properties when it stops. Reduced motion is as before: no dash movement, held dots at full opacity. The dash moves the same 8px per 0.7s and the fade has the same 1.2s period and .45 low. Measured (zzload harness, not committed: a local fake Anthropic upstream, five parallel /v1/messages streams from one client with tool_use turns and tool_result histories, 15ms per event, Playwright on ?view=routing; browser CPU-s per 5s, mean of the loaded samples, before/after runs alternated at the same tree): - mote (macOS 27, Chromium): 1.15/1.13 -> 0.89/0.90 (wires only); Claude Code subagent shape (one session id, sidechain transcripts growing under a sandbox HOME): 1.24 -> 0.99. Gateway 2.23 vs 2.22. - xiaomi-gpu (Windows 11, Chromium): 1.55/1.59 -> 1.21/1.22, about 31% to 24% of a core. Gateway 4.2-5.2 in both. - What's left: the fliers' rAF loop and wing flaps (~0.3 on mote), the composited dot pulses, and the page's own work. Run on 578053d6a; after the rebase onto710f0290c, go test ./internal/gui and routing-answered-still (20 of 20) ran again at the pushed tree: - routing-answered-still, both engines, en, 1100 and 420: ok. It now checks the copies have no CSS animation, their dash moves with 1-30 style writes a second, a held dot has no animation and its opacity changes, and the timer stops (no property, no writes) after the answer. - Broken by hand: put the rtflow animation back on .rt-flows path; routing-answered-still goes red (animated: 2 !== 0) in Chromium. - routing-*.test.cjs: the reds are the same on578053d6awithout this change (#5392 intent-entry, #3799 row-swap, #5586 context-fold, #4627 order-unknown, #5161 credits); rule-drag in WebKit fails one random locale a run on main too (#3789). - go test ./internal/gui (asset budgets) on mote: ok (164s). - Full suite (go test -timeout 45m ./...): started after the push and tag, as fixes ship at once; any red it finds gets its own issue. Not tried: the reporter's provider and a real Claude Code; the claude subscription bridge (claudetui) with real accounts; WebView2 inside the real Wails app (Playwright Chromium on Windows stands in for it); masking's model on Windows; TLS upstreams. Reported-by: chenxiang (Discord)
This commit is contained in:
@@ -1904,6 +1904,34 @@ function routingPage(part) {
|
||||
// GPU each frame one flowed, 31 fps with both groups open (#3164)
|
||||
const flowing = new Map();
|
||||
let flowAsked = 0, sight = null, scrolled = 0;
|
||||
// The copies' dashes move 8px each .7s (--rt-dash on flows), and a dot
|
||||
// held at an account while it answers fades to .45 and back each 1.2s
|
||||
// (--rt-held on sky), both set from a timer 15 times a second, not by
|
||||
// CSS animations: Chromium draws an animated dash offset, or an SVG
|
||||
// dot's opacity under its drop shadow, on the main thread every frame,
|
||||
// and each flowing wire spans the stage. With five requests in flight
|
||||
// the Routing page took a quarter of a core and more in WebView2
|
||||
// (chenxiang, #5467). The timer runs only while a wire flows or a dot
|
||||
// is held, in sight and with motion on.
|
||||
const SLOW_EVERY = 1000 / 15;
|
||||
let slowTimer = 0;
|
||||
const slowNeeded = () => (flowing.size > 0 || holds.size > 0) && shown() && !still();
|
||||
function slowTick() {
|
||||
if (!slowNeeded()) {
|
||||
// stopped where it was, a dot held on would stay faded and still
|
||||
clearInterval(slowTimer); slowTimer = 0;
|
||||
flows.style.removeProperty("--rt-dash"); sky.style.removeProperty("--rt-held");
|
||||
return;
|
||||
}
|
||||
const now_ = performance.now();
|
||||
if (flowing.size) flows.style.setProperty("--rt-dash", (-(now_ % 700) / 700 * 8).toFixed(2) + "px");
|
||||
if (holds.size) sky.style.setProperty("--rt-held", (1 - .55 * (1 - Math.cos(2 * Math.PI * (now_ % 1200) / 1200)) / 2).toFixed(3));
|
||||
}
|
||||
function slowMove() {
|
||||
if (slowTimer || !slowNeeded()) return;
|
||||
slowTick();
|
||||
slowTimer = setInterval(slowTick, SLOW_EVERY);
|
||||
}
|
||||
const flowSoon = () => { if (!flowAsked) flowAsked = requestAnimationFrame(() => { flowAsked = 0; flowNear(); }); };
|
||||
function flowNear() {
|
||||
const live = new Set([...wires.querySelectorAll("path.live[d]")].filter((p) => !p.classList.contains("rest")));
|
||||
@@ -1929,6 +1957,7 @@ function routingPage(part) {
|
||||
if (dash) f.copy.style.setProperty("stroke-dasharray", dash);
|
||||
else f.copy.style.removeProperty("stroke-dasharray");
|
||||
}
|
||||
slowMove();
|
||||
}
|
||||
// dashFor is a wire's dashes from top to bottom, measured from its d,
|
||||
// which is magpie's own M, L, Q and C: WebKit's getPointAtLength took
|
||||
@@ -5010,6 +5039,7 @@ function routingPage(part) {
|
||||
dot.classList.add("held");
|
||||
holds.set(dot, row);
|
||||
holdAll();
|
||||
slowMove();
|
||||
await until(() => g !== gen || rt().tries[i].done);
|
||||
holds.delete(dot);
|
||||
if (g !== gen) break;
|
||||
@@ -5333,6 +5363,7 @@ function routingPage(part) {
|
||||
// Visibility events can arrive after the browser has suspended frames, so
|
||||
// finish hidden work here too. The first visible frame alone owns resume.
|
||||
function start() {
|
||||
slowMove();
|
||||
const waking = !!sightWait; // the poll waited: it reads what came meanwhile
|
||||
inSightAgain();
|
||||
countdown();
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
the wires that don't move aren't drawn again each frame (#3164) */
|
||||
.rt-wires path.flown { visibility: hidden; animation: none; }
|
||||
.rt-flows { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; will-change: transform; }
|
||||
.rt-flows path { fill: none; stroke: var(--agent, var(--muted)); stroke-width: 1.5; stroke-dasharray: 3 5; animation: rtflow .7s linear infinite; }
|
||||
/* its dashes move by --rt-dash, which a timer sets 15 times a second
|
||||
(slowTick): an animated offset was drawn again every frame */
|
||||
.rt-flows path { fill: none; stroke: var(--agent, var(--muted)); stroke-width: 1.5; stroke-dasharray: 3 5; stroke-dashoffset: var(--rt-dash, 0); }
|
||||
@keyframes rtflow { to { stroke-dashoffset: -8; } }
|
||||
/* the magpies: one carries each request out, another brings its answer
|
||||
back — the dot at the tip of its beak. They fly along the wires and
|
||||
@@ -37,8 +39,9 @@
|
||||
.rt-sky .pkt.back { fill: var(--card); stroke: var(--agent, var(--fg)); stroke-width: 2.25; }
|
||||
.rt-sky .pkt.back.err { fill: var(--agent, var(--card)); stroke: var(--red); }
|
||||
.rt-sky path.via { fill: none; stroke: none; }
|
||||
.rt-sky .pkt.held { animation: rtheld 1.2s ease-in-out infinite; }
|
||||
@keyframes rtheld { 50% { opacity: .45; } }
|
||||
/* a dot held at an account fades by --rt-held, from the same timer: an
|
||||
animated opacity under its shadow was drawn again every frame */
|
||||
.rt-sky .pkt.held { opacity: var(--rt-held, 1); }
|
||||
.rt-flier { color: var(--fg); }
|
||||
.rt-flier .body, .rt-flier .tail, .rt-flier .wing path:first-child, .rt-flier .wing.far { fill: currentColor; }
|
||||
.rt-flier .wing.far { opacity: .45; }
|
||||
@@ -242,7 +245,7 @@
|
||||
.rt-time .vendor { --rt-time: var(--fg-2); }
|
||||
.rt-off { padding: 18px 4px; text-align: center; color: var(--muted); font-size: 13px; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.rt-wires path.live, .rt-flows path, .rt-sky .pkt.held, .rt-accts li.new, .rt-accts li.hit, .rt-hub.tick, .rt-src.tick, .rt-cap.in, .masking .pii { animation: none; }
|
||||
.rt-wires path.live, .rt-accts li.new, .rt-accts li.hit, .rt-hub.tick, .rt-src.tick, .rt-cap.in, .masking .pii { animation: none; }
|
||||
.rt-accts li.now .dot::after, .rt-steps li.wait::after { animation: none; }
|
||||
.rt-accts li { transition: none; }
|
||||
}
|
||||
|
||||
@@ -118,10 +118,31 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const live = [...document.querySelectorAll(".rt-wires path.live[d]")], copies = [...document.querySelectorAll(".rt-flows path[d]")];
|
||||
return {
|
||||
hidden: live.filter((p) => getComputedStyle(p).visibility === "hidden" && getComputedStyle(p).animationName === "none").length,
|
||||
moving: copies.filter((p) => getComputedStyle(p).animationName === "rtflow").length,
|
||||
animated: copies.filter((p) => getComputedStyle(p).animationName !== "none").length,
|
||||
layer: getComputedStyle(document.querySelector(".rt-flows")).willChange,
|
||||
};
|
||||
}), { hidden: 2, moving: 2, layer: "transform" });
|
||||
}), { hidden: 2, animated: 0, layer: "transform" });
|
||||
// the copies' dashes move, from a timer 15 times a second and not
|
||||
// a CSS animation, which Chromium drew on the main thread every
|
||||
// frame: with five requests in flight that was a quarter of a core
|
||||
// in WebView2 (chenxiang, #5467). The dot held at the account fades
|
||||
// from the same timer, not a CSS animation either.
|
||||
const offsets = () => page.evaluate(() => [...document.querySelectorAll(".rt-flows path[d]")].map((p) => getComputedStyle(p).strokeDashoffset).join());
|
||||
const was = await offsets();
|
||||
await page.waitForFunction((was) => [...document.querySelectorAll(".rt-flows path[d]")].map((p) => getComputedStyle(p).strokeDashoffset).join() !== was, was);
|
||||
const ticks = await page.evaluate(() => new Promise((res) => {
|
||||
let n = 0;
|
||||
const o = new MutationObserver(() => n++);
|
||||
o.observe(document.querySelector(".rt-flows"), { attributes: true, attributeFilter: ["style"] });
|
||||
setTimeout(() => { o.disconnect(); res(n); }, 1000);
|
||||
}));
|
||||
assert(ticks >= 1 && ticks <= 30, `the dashes moved ${ticks} times in a second, not every frame`);
|
||||
// the dot let go at the account fades and comes back, by the timer
|
||||
await page.waitForFunction(() => document.querySelector(".rt-sky .pkt.held"), null, { timeout: 15000 });
|
||||
assert.equal(await page.evaluate(() => getComputedStyle(document.querySelector(".rt-sky .pkt.held")).animationName), "none");
|
||||
const fade = () => page.evaluate(() => getComputedStyle(document.querySelector(".rt-sky .pkt.held")).opacity);
|
||||
const fadeWas = await fade();
|
||||
await page.waitForFunction((was) => getComputedStyle(document.querySelector(".rt-sky .pkt.held")).opacity !== was, fadeWas);
|
||||
assert.match((await fold.locator("em").textContent()).trim(), new RegExp("^ag-2: " + (await say("answering…")).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
||||
|
||||
// opened, the key with the request is the one that flows
|
||||
@@ -140,6 +161,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(s.lit, 2, "the fold's wire and the key's");
|
||||
await page.waitForFunction(() => !document.querySelector(".rt-flows path"));
|
||||
assert.equal(await page.locator(".rt-wires path.flown").count(), 0);
|
||||
// and nothing flowing, the timer is gone: --rt-dash is let go and
|
||||
// set no more
|
||||
await page.waitForFunction(() => !document.querySelector(".rt-flows").style.getPropertyValue("--rt-dash"));
|
||||
assert.equal(await page.evaluate(() => new Promise((res) => {
|
||||
let n = 0;
|
||||
const o = new MutationObserver(() => n++);
|
||||
o.observe(document.querySelector(".rt-flows"), { attributes: true, attributeFilter: ["style"] });
|
||||
setTimeout(() => { o.disconnect(); res(n); }, 400);
|
||||
})), 0);
|
||||
|
||||
// a reload shows it the same: lit and still
|
||||
await page.reload();
|
||||
|
||||
Reference in New Issue
Block a user