diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 0dab25a01..d53cb1b87 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -64,6 +64,10 @@ function routingPage(part) { const wires = document.createElementNS(NS, "svg"); wires.setAttribute("class", "rt-wires"); wires.setAttribute("aria-hidden", "true"); + // the wires flowing, drawn over the rest in an svg of their own (flowNear) + const flows = document.createElementNS(NS, "svg"); + flows.setAttribute("class", "rt-flows"); + flows.setAttribute("aria-hidden", "true"); const srcs = el("div", "rt-srcs"); // an agent's node each const hub = el("div", "rt-node rt-hub"); const logo = document.createElementNS(NS, "svg"); @@ -77,7 +81,7 @@ function routingPage(part) { const sky = document.createElementNS(NS, "svg"); sky.setAttribute("class", "rt-sky"); sky.setAttribute("aria-hidden", "true"); - stage.append(wires, srcs, hub, list, sky); + stage.append(wires, flows, srcs, hub, list, sky); const foot = el("div", "rt-foot"); const cap = el("p", "rt-cap"); cap.setAttribute("aria-live", "polite"); @@ -1500,13 +1504,16 @@ function routingPage(part) { // sight (dashFor). Nothing is laid out for it: where the // stage and what is in sight were is kept by layout, which reads them // anyway (sight), and the view's scroll since by its scroll events. - // Reading them here laid the stage out again after each update + // Reading them here laid the stage out again after each update. + // Each is drawn by a copy in flows, a layer of its own, and itself hidden: + // in the svg of every wire, Chromium (WebView2) drew all 800 again on the + // GPU each frame one flowed, 31 fps with both groups open (#3164) const flowing = new Map(); let flowAsked = 0, sight = null, scrolled = 0; 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"))); - for (const p of flowing.keys()) if (!live.has(p)) { p.style.removeProperty("stroke-dasharray"); flowing.delete(p); } + for (const [p, f] of flowing) if (!live.has(p)) { f.copy.remove(); p.classList.remove("flown"); flowing.delete(p); } if (!live.size || !sight) return; // in the stage's own terms, a screen more each way, in steps of 200px // so a scroll redashes a wire only now and then @@ -1515,14 +1522,18 @@ function routingPage(part) { for (const p of live) { // the same wire with the same in sight is dashed as it was: this is // asked after every update - const d = p.getAttribute("d"), key = `${d}|${top}|${bottom}`; - if (flowing.get(p)?.key === key) continue; + const d = p.getAttribute("d"), hue = p.style.getPropertyValue("--agent"), key = `${d}|${hue}|${top}|${bottom}`; + let f = flowing.get(p); + if (f?.key === key) continue; + if (!f) { f = { copy: document.createElementNS(NS, "path"), dash: "" }; flows.appendChild(f.copy); flowing.set(p, f); p.classList.add("flown"); } + f.key = key; + if (f.copy.getAttribute("d") !== d) f.copy.setAttribute("d", d); + if (hue) f.copy.style.setProperty("--agent", hue); else f.copy.style.removeProperty("--agent"); const dash = dashFor(d, top, bottom); - const was = flowing.get(p)?.dash; - flowing.set(p, { key, dash }); - if (was === dash) continue; - if (dash) p.style.setProperty("stroke-dasharray", dash); - else p.style.removeProperty("stroke-dasharray"); + if (f.dash === dash) continue; + f.dash = dash; + if (dash) f.copy.style.setProperty("stroke-dasharray", dash); + else f.copy.style.removeProperty("stroke-dasharray"); } } // dashFor is a wire's dashes from top to bottom, measured from its d, @@ -1717,6 +1728,7 @@ function routingPage(part) { } sight = { at: r.top, scroll: scrolled, lo: Math.max(0, v.top), hi: Math.min(innerHeight, v.bottom) }; wires.setAttribute("viewBox", `0 0 ${r.width} ${r.height}`); + flows.setAttribute("viewBox", `0 0 ${r.width} ${r.height}`); sky.setAttribute("viewBox", `0 0 ${r.width} ${r.height}`); for (const [p, d] of sets) { if (d === null) { if (p.hasAttribute("d")) p.removeAttribute("d"); } diff --git a/internal/gui/assets/plugins/routing/routing.css b/internal/gui/assets/plugins/routing/routing.css index ac0221e9a..dde4ce87d 100644 --- a/internal/gui/assets/plugins/routing/routing.css +++ b/internal/gui/assets/plugins/routing/routing.css @@ -13,6 +13,11 @@ /* lit: the way the request shown went, over; only a request in flight flows (#2386) */ .rt-wires path.lit { stroke: var(--agent, var(--muted)); } .rt-wires path.rest { stroke-dasharray: 2 6; opacity: .45; } +/* a flowing wire is drawn by its copy in .rt-flows, a layer of its own, so + 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; } @keyframes rtflow { to { stroke-dashoffset: -8; } } /* the magpies, over the nodes: one carries each request out, another brings its answer back — the dot at the tip of its beak */ @@ -168,7 +173,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-accts li.now .dot, .rt-wires path.live, .rt-sky .pkt.held, .rt-accts li.new, .rt-accts li.hit, .rt-hub.tick, .rt-src.tick, .rt-cap.in, .rt-steps li.wait::before, .masking .pii { animation: none; } + .rt-accts li.now .dot, .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, .rt-steps li.wait::before, .masking .pii { animation: none; } .rt-accts li { transition: none; } } /* The narrow and wide layouts below go by a box's own width, as container diff --git a/internal/gui/tests/routing-answered-still.test.cjs b/internal/gui/tests/routing-answered-still.test.cjs index 66a4cdfeb..43f79f3c6 100644 --- a/internal/gui/tests/routing-answered-still.test.cjs +++ b/internal/gui/tests/routing-answered-still.test.cjs @@ -104,6 +104,23 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(s.moving, 1); assert.equal(s.flowing, 2, "the agent's wire and the fold's"); assert.equal(s.lit, 0); + // each flows as its copy in .rt-flows, a layer of its own, and is + // itself hidden: in the svg of every wire, WebView2 drew all of them + // again each frame one flowed (#3164) + // (a wire's d set anew is copied on the next frame) + const same = () => { + const ds = (q) => [...document.querySelectorAll(q)].map((p) => p.getAttribute("d")).sort().join(); + return document.querySelectorAll(".rt-flows path[d]").length === 2 && ds(".rt-wires path.live[d]") === ds(".rt-flows path[d]"); + }; + await page.waitForFunction(same); + assert.deepEqual(await page.evaluate(() => { + 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, + layer: getComputedStyle(document.querySelector(".rt-flows")).willChange, + }; + }), { hidden: 2, moving: 2, layer: "transform" }); 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 @@ -120,6 +137,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(s.moving, 0); assert.equal(s.flowing, 0); 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); // a reload shows it the same: lit and still await page.reload();