routing: a flowing wire is drawn in a layer of its own, so WebView2 doesn't redraw every wire each frame (#3164)
On Windows the Routing page with an 800-key group open ran at 31 fps. A flowing wire (stroke-dashoffset animated) sat in the one svg of every wire, 993x36215 px with 803 paths, and Chromium re-rasterized that whole svg on the GPU each frame: CrGpuMain was busy 5s in 5s, 3.6s of it in RasterDecoderImpl::DoRasterCHROMIUM. Hiding the wires svg gave 118 fps, taking the dash animation off the wires 102 fps; WebKit (macOS) was never slow here. Now flowNear draws each flowing wire by a copy in .rt-flows, an svg over the wires with will-change: transform, with the wire's d, --agent and the dashes it worked out, and hides the wire itself (.flown: hidden, no animation). The look is the same; the svg of every wire no longer changes while a request flows. Reduced motion stops the copies too. Real WebView2 (Edg/155, Windows 11, Radeon 8060S), the magpie window at 1281x1128 CSS px, dpr 1.1, a sandbox HOME with two providers of 499 and 299 keys in one group, both folds open, a request every 0.3s through a fake upstream; v0.1.1587's release exe against this commit built with GOOS=windows: steady 15s x3 31 fps, 89-94 frames >40ms -> 114 fps, 4-9 >40ms scroll 12s 58 fps -> 88 fps fold+unfold 4s 41 fps -> 103 fps The same injected by hand into the old page first: 38 -> 48 fps with the copies in a plain svg, 94 fps with will-change, so the layer is what does it. Test: routing-answered-still checks that each flowing wire has a copy with its d, animated, in a will-change layer, the wire itself hidden and still, and that nothing is left once the request is done. Without this change .rt-flows doesn't exist and it times out. Run at this commit (rebased on origin/main5a94eec3a, which touches nothing under routing): routing-answered-still 20 of 20 alone in chromium and webkit. Eleven routing GUI files at concurrency 3 against the base44a626bedunder load ~74: 127 pass / 45 fail here, 123 / 49 on the base; the reds are rule-editor files that fail the same on the base (#3408). routing-keys-fold had 2 reds here under that load (its "3 resting" wait, not a wire) and is 32 of 32 alone 3 of 3. go test ./internal/gui ok; GOOS=linux and GOOS=windows go vet -tags nogui ok. Not tried: WebKitGTK.
This commit is contained in:
@@ -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"); }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user