diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index a7d85d7d0..3754cce92 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -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(); diff --git a/internal/gui/assets/plugins/routing/routing.css b/internal/gui/assets/plugins/routing/routing.css index 5853d54b3..09d09414c 100644 --- a/internal/gui/assets/plugins/routing/routing.css +++ b/internal/gui/assets/plugins/routing/routing.css @@ -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; } } diff --git a/internal/gui/tests/routing-answered-still.test.cjs b/internal/gui/tests/routing-answered-still.test.cjs index 3840ba0b6..f1843a6fc 100644 --- a/internal/gui/tests/routing-answered-still.test.cjs +++ b/internal/gui/tests/routing-answered-still.test.cjs @@ -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();