routing: a live dot pulses by transform and opacity, on the compositor
Routing with requests in flight kept the renderer busy (unscientific9: "高并发路由页面" is slow). Every live dot (the answering account, the live dot, a waiting try, probe, preview target and step) pulsed by a box-shadow keyframe, which Chrome and WebKit run on the main thread: the page was restyled and repainted every frame for as long as anything was under way. Each pulse is now a ::after disk that grows and fades by transform and opacity alone, which the compositor runs without a paint. A muted dot's disk lies behind it (its parent isolates it, the disk at z-index -1), so its colour isn't tinted; a filled dot's disk is its own colour. Sizes match the old shadow (6px each side). Reduced motion and a quiet account still show no pulse. Measured on mote (headless Chromium 1280x820, app mode, sandbox HOME with a 300k-row ledger, a fake upstream, Routing held 30 s, Chrome trace): - 6 in flight: Paint 5714 / 5598 ms -> 3055 / 2804 ms; main-thread RunTask 7448 / 7148 -> 6851 / 6320 ms - 64 in flight: Paint 4408 / 4217 -> 1746 / 1759 ms; RunTask 8056 / 7921 -> 7405 / 7434 ms Most of what is left is the wires' rtflow (stroke-dashoffset, also main thread): with it off as well RunTask is 3415 ms at 6 in flight, and with every animation off 2560 ms. That one changes how the wires look, so it is filed separately, not changed here. Test: routing-pulse-composited.test.cjs, with the real stylesheets in Chromium and WebKit, light and dark: every endless animation of each live dot animates only transform and opacity, each live dot pulses, a muted dot's centre keeps its colour, and no dot moves. reduce-motion, routing-idle-frame and routing-live-bytes read the pulse from ::after now. Run via mote-run: routing-pulse-composited, fonts, reduce-motion, routing-idle-frame, routing-live-bytes, routing-wait-dot and status-dot-shape, 101 of 101 ok. Broken by hand: with the old routing.css the new test fails in both engines. Not run before the push: the wider run of the 359 GUI files that load Routing or the font code; its reds, if any, get issues. Not tried: a real Mac's window (WebKit in the app) on a display; the numbers are headless Chromium. Reported-by: unscientific9 (on Discord)
This commit is contained in:
@@ -138,12 +138,29 @@
|
||||
.rt-accts li.on em { color: var(--fg); }
|
||||
.rt-accts li.on .bar i { background: var(--fg); }
|
||||
.rt-accts li.on .dot { background: var(--fg); border-color: var(--fg); }
|
||||
.rt-accts li.now .dot { animation: rtlive 1.8s infinite; }
|
||||
@keyframes rtlive { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--fg) 40%, transparent); } 70%, 100% { box-shadow: 0 0 0 6px transparent; } }
|
||||
/* A live dot's pulse: a disk 6px wider all round grows from the dot and
|
||||
fades. It moves by transform and opacity, on the compositor: as a
|
||||
box-shadow it repainted the page every frame while requests were in
|
||||
flight, and 64 of them kept a core half busy (unscientific9). A muted
|
||||
dot's disk goes behind it, in a parent that isolates it; a filled one's
|
||||
is the dot's own colour, so it may lie on top. */
|
||||
.rt-accts li.now .dot, .rt-livedot.on, :is(.rt-req, .rt-probe).wait .to i, .ps-dst.wait > i { position: relative; }
|
||||
.rt-accts li.now .dot::after, .rt-livedot.on::after, :is(.rt-req, .rt-probe).wait .to i::after, .ps-dst.wait > i::after, .rt-steps li.wait::after {
|
||||
content: ""; position: absolute; inset: 0; border-radius: 50%; background: color-mix(in srgb, var(--fg) 40%, transparent); opacity: 0; pointer-events: none;
|
||||
animation: rtlive 1.8s infinite;
|
||||
}
|
||||
.rt-accts li.now .dot::after { inset: -1.5px; animation-name: rtlive-dot; }
|
||||
:is(.rt-req, .rt-probe).wait .to, .ps-dst.wait, .rt-steps li.wait { isolation: isolate; }
|
||||
:is(.rt-req, .rt-probe).wait .to i::after, .ps-dst.wait > i::after, .rt-steps li.wait::after { z-index: -1; }
|
||||
.rt-steps li.wait::after { inset: auto; left: 5px; top: .5em; width: 6px; height: 6px; }
|
||||
/* 6px each side: a 6px dot grows to 18px, the 8px account dot to 20px */
|
||||
@keyframes rtlive { 0% { transform: scale(1); opacity: 1; } 70%, 100% { transform: scale(3); opacity: 0; } }
|
||||
@keyframes rtlive-dot { 0% { transform: scale(1); opacity: 1; } 70%, 100% { transform: scale(2.5); opacity: 0; } }
|
||||
.rt-accts li.low em { color: var(--fg-2); }
|
||||
.rt-accts li.rest { border-style: dashed; }
|
||||
/* a reply still out with no content for 15s: the dot stops pulsing */
|
||||
.rt-accts li.quiet .dot { background: var(--amber); border-color: var(--amber); animation: none; }
|
||||
.rt-accts li.quiet .dot { background: var(--amber); border-color: var(--amber); }
|
||||
.rt-accts li.quiet .dot::after { animation: none; }
|
||||
.rt-accts li.rest > :not(.tag) { opacity: .5; }
|
||||
.rt-accts li.rest em { color: var(--red); opacity: .85; }
|
||||
.rt-accts li.left { border-style: dotted; }
|
||||
@@ -204,7 +221,7 @@
|
||||
.rt-steps li.aside::before { background: none; border: 1px solid var(--muted); width: 4px; height: 4px; }
|
||||
.rt-steps li.ok::before { background: var(--green); }
|
||||
.rt-steps li.bad::before { background: var(--red); -webkit-mask: var(--x-mark) center / contain no-repeat; mask: var(--x-mark) center / contain no-repeat; border-radius: 0; transform: scale(1.5); }
|
||||
.rt-steps li.wait::before { animation: rtlive 1.8s infinite; }
|
||||
|
||||
/* where a try's time went: one stacked bar, magpie's, the network's and
|
||||
the vendor's told apart by a swatch, each part named with its time */
|
||||
.rt-time { display: grid; gap: 5px; max-width: 560px; }
|
||||
@@ -221,7 +238,8 @@
|
||||
.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-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-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-accts li.now .dot::after, .rt-steps li.wait::after { animation: none; }
|
||||
.rt-accts li { transition: none; }
|
||||
}
|
||||
/* The narrow and wide layouts below go by a box's own width, as container
|
||||
@@ -342,7 +360,7 @@
|
||||
:is(.rt-req, .rt-probe).moved .to i { background: var(--accent); }
|
||||
:is(.rt-req, .rt-probe).bad .to { color: var(--red); }
|
||||
:is(.rt-req, .rt-probe).bad .to i { background: var(--red); -webkit-mask: var(--x-mark) center / contain no-repeat; mask: var(--x-mark) center / contain no-repeat; border-radius: 0; transform: scale(1.5); }
|
||||
:is(.rt-req, .rt-probe).wait .to i { background: var(--muted); animation: rtlive 1.8s infinite; }
|
||||
:is(.rt-req, .rt-probe).wait .to i { background: var(--muted); }
|
||||
/* the reasoning keeps to its own box: what it was asked at is cut first,
|
||||
then what it was sent at, never drawn over the numbers beside it (#435) */
|
||||
:is(.rt-req, .rt-probe) .to .ef { flex: 0 1 auto; display: flex; min-width: 0; margin-left: -2px; color: var(--muted); }
|
||||
@@ -525,8 +543,7 @@ button.rt-session { cursor: pointer; }
|
||||
.rt-act.rt-keys:focus-visible { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
|
||||
.rt-livedot { width: 6px; height: 6px; margin-left: 7px; border-radius: 50%; background: var(--green); --fg: var(--green); }
|
||||
/* it pulses while a request is under way only (#2827) */
|
||||
.rt-livedot.on { animation: rtlive 1.8s infinite; }
|
||||
@media (prefers-reduced-motion: reduce) { .rt-livedot.on { animation: none; } }
|
||||
@media (prefers-reduced-motion: reduce) { .rt-livedot.on::after { animation: none; } }
|
||||
/* routing groups, and the providers routing over several of their own */
|
||||
.rt-gsec { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin-top: 16px; }
|
||||
.rt-gsec .row-head .note { margin-right: 6px; }
|
||||
@@ -976,7 +993,7 @@ body.window .rt-gedit > .bar { --vfoot: 8px; }
|
||||
.ps-name small { margin-left: 4px; font-size: 10.5px; font-weight: 400; color: var(--muted); }
|
||||
.ps-dst > i { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
|
||||
.ps-dst.bad > i { background: var(--red); -webkit-mask: var(--x-mark) center / contain no-repeat; mask: var(--x-mark) center / contain no-repeat; border-radius: 0; transform: scale(1.5); }
|
||||
.ps-dst.wait > i { background: var(--muted); animation: rtlive 1.8s infinite; }
|
||||
.ps-dst.wait > i { background: var(--muted); }
|
||||
.ps-hub { position: relative; z-index: 1; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--fg); background: var(--card); box-shadow: inset 0 0 0 1px var(--line), 0 1px 3px rgba(0, 0, 0, .08); }
|
||||
.ps-hub svg { width: 24px; height: 24px; }
|
||||
.ps-hub.busy { animation: ps-ring 1.8s ease-out infinite; }
|
||||
@@ -1026,7 +1043,7 @@ body.window .rt-gedit > .bar { --vfoot: 8px; }
|
||||
.pr-line { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; min-width: 0; }
|
||||
.pr-line .pr-to { flex: 1 1 auto; }
|
||||
.pr-req .meta { flex: none; max-width: 100%; margin-left: auto; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
|
||||
@media (prefers-reduced-motion: reduce) { .pr-req.wait .pr-to > i, .ps-dst.wait > i, .ps-hub.busy, .ps-dot.wait { animation: none; } }
|
||||
@media (prefers-reduced-motion: reduce) { .pr-req.wait .pr-to > i, .ps-hub.busy, .ps-dot.wait { animation: none; } .ps-dst.wait > i::after { animation: none; } }
|
||||
@supports not (grid-template-columns: subgrid) {
|
||||
@media (max-width: 700px) {
|
||||
.rt-reqs { --rt-tpl: auto minmax(0, 1fr); }
|
||||
|
||||
@@ -59,7 +59,7 @@ const looks = (page) => page.evaluate(async () => {
|
||||
const dot = document.createElement("i");
|
||||
dot.className = "rt-livedot on";
|
||||
document.body.append(dot);
|
||||
const anim = getComputedStyle(dot).animationName;
|
||||
const anim = getComputedStyle(dot, "::after").animationName;
|
||||
dot.remove();
|
||||
const box = document.createElement("div");
|
||||
box.className = "signing";
|
||||
|
||||
@@ -96,7 +96,7 @@ const init = () => {
|
||||
return n;
|
||||
};
|
||||
// the live dot's pulse, running or not
|
||||
window.__pulses = () => [...document.querySelectorAll(".rt-livedot")].filter((d) => d.getAnimations().some((a) => a.playState === "running")).length;
|
||||
window.__pulses = () => [...document.querySelectorAll(".rt-livedot")].filter((d) => d.getAnimations({ subtree: true }).some((a) => a.playState === "running")).length;
|
||||
window.requestAnimationFrame = (cb) => {
|
||||
// a loop of the core's (app.js's sidebar spring, navTopStep) is a
|
||||
// global; the Routing plugin's is in its own scope
|
||||
|
||||
@@ -106,7 +106,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
// quiet for 20s: the dot stops, and the account says the numbers only
|
||||
send(route({ bytes: 3 * 1048576 + 600000, estTok: 1500, contentAt: Date.now() - 20000 }));
|
||||
await account.and(page.locator("li.quiet")).waitFor();
|
||||
assert.equal(await account.locator(".dot").evaluate((d) => getComputedStyle(d).animationName), "none");
|
||||
assert.equal(await account.locator(".dot").evaluate((d) => getComputedStyle(d, "::after").animationName), "none");
|
||||
em = (await account.locator("em").textContent()).trim();
|
||||
assert.ok(!em.includes(answering) && em.includes("3.6 MiB"), em);
|
||||
assert.ok((await cells())[2].includes(await say("{n} s", { n: 20 })) || (await cells())[2].includes(await say("{n} s", { n: 21 })), (await cells())[2]);
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
// Routing's live dots pulse on the compositor (unscientific9 on Discord:
|
||||
// Routing stuck with many requests in flight). The pulse was a box-shadow
|
||||
// keyframe, which repainted the page and recalculated its style every
|
||||
// frame for as long as any request was under way: 64 in flight kept the
|
||||
// renderer's main thread about a third busy. Each live dot's pulse is now
|
||||
// a disk that grows and fades by transform and opacity alone. Checked with
|
||||
// the real stylesheets in both engines: every endless animation of a live
|
||||
// dot moves only those two, each live dot does pulse, a muted dot's disk
|
||||
// lies behind it (its centre keeps its colour), and the dot doesn't move.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
|
||||
// each: its name, its markup, the dot, the pseudo-element drawing it, and
|
||||
// whether the dot is muted (its pulse must go behind it)
|
||||
const DOTS = [
|
||||
["account", '<ul class="rt-accts"><li class="on now"><span class="dot"></span><b>acct</b><em>answering</em></li></ul>', ".dot", null, false],
|
||||
["live dot", '<span class="rt-livedot on"></span>', ".rt-livedot", null, false],
|
||||
["waiting try", '<div class="rt-req wait"><span class="to"><i></i>waiting</span></div>', ".to i", null, true],
|
||||
["waiting probe", '<div class="rt-probe wait"><span class="to"><i></i>waiting</span></div>', ".to i", null, true],
|
||||
["waiting preview", '<span class="ps-node ps-dst wait"><i></i><span class="ps-name">a</span></span>', ".ps-dst > i", null, true],
|
||||
["waiting step", '<ul class="rt-steps"><li class="wait">asking</li></ul>', ".rt-steps li", "::before", true],
|
||||
];
|
||||
// what the compositor animates without a paint
|
||||
const COMPOSITED = new Set(["transform", "opacity"]);
|
||||
|
||||
const page = (theme) => `<!doctype html><html data-theme="${theme}"><head><meta charset="utf-8">
|
||||
<link rel="stylesheet" href="/app.css"><link rel="stylesheet" href="/plugins/routing/routing.css">
|
||||
<style>body { margin: 0; padding: 24px; background: var(--card); } .one { padding: 14px 20px; } .rt-steps, .rt-accts { margin: 0; padding: 0; list-style: none; }</style>
|
||||
</head><body>${DOTS.map(([, html]) => `<div class="one">${html}</div>`).join("")}</body></html>`;
|
||||
|
||||
for (const engine of process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"]) {
|
||||
test(engine + ": Routing's live dots pulse by transform and opacity only", async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await t.test(theme, async () => {
|
||||
const context = await browser.newContext({ viewport: { width: 600, height: 700 }, colorScheme: theme, reducedMotion: "no-preference" });
|
||||
t.after(() => context.close());
|
||||
const p = await context.newPage();
|
||||
await p.route("**/*", async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.pathname === "/") return route.fulfill({ contentType: "text/html", body: page(theme) });
|
||||
if (url.pathname.endsWith(".css")) return route.fulfill({ contentType: "text/css", body: await fs.readFile(path.join(assets, url.pathname)) });
|
||||
return route.fulfill({ status: 404, body: "" });
|
||||
});
|
||||
await p.goto("http://magpie.test/");
|
||||
|
||||
for (let i = 0; i < DOTS.length; i++) {
|
||||
const [name, , sel, pseudo, muted] = DOTS[i];
|
||||
const one = p.locator(`.one >> nth=${i}`);
|
||||
const r = await one.evaluate((box) => box.getAnimations({ subtree: true })
|
||||
.filter((a) => a.effect.getComputedTiming().iterations === Infinity)
|
||||
.map((a) => ({ name: a.animationName, props: [...new Set(a.effect.getKeyframes().flatMap((k) => Object.keys(k)))]
|
||||
.filter((k) => !["offset", "computedOffset", "easing", "composite"].includes(k)) })));
|
||||
assert.ok(r.length > 0, `${name}: the live dot pulses`);
|
||||
for (const a of r) {
|
||||
const off = a.props.filter((k) => !COMPOSITED.has(k));
|
||||
assert.deepEqual(off, [], `${name}: ${a.name} animates ${off.join(", ")}, which repaints every frame`);
|
||||
}
|
||||
if (!muted) continue;
|
||||
// the disk at its start, the dot's own size and fully drawn: a
|
||||
// muted dot's centre is still the dot's colour, so it lies behind
|
||||
const centre = async () => {
|
||||
const b = await one.locator(sel).first().evaluate((e, pseudo) => {
|
||||
const r = e.getBoundingClientRect(), s = getComputedStyle(e, pseudo);
|
||||
const x = pseudo ? r.left + parseFloat(s.left) + parseFloat(s.width) / 2 : r.left + r.width / 2;
|
||||
const y = pseudo ? r.top + parseFloat(s.top) + parseFloat(s.height) / 2 : r.top + r.height / 2;
|
||||
return { x: Math.round(x), y: Math.round(y) };
|
||||
}, pseudo);
|
||||
const png = await p.screenshot({ clip: { x: b.x, y: b.y, width: 1, height: 1 } });
|
||||
return p.evaluate(async (b64) => {
|
||||
const img = new Image();
|
||||
img.src = "data:image/png;base64," + b64;
|
||||
await img.decode();
|
||||
const c = document.createElement("canvas");
|
||||
c.width = c.height = 1;
|
||||
const g = c.getContext("2d");
|
||||
g.drawImage(img, 0, 0);
|
||||
return [...g.getImageData(0, 0, 1, 1).data.slice(0, 3)];
|
||||
}, png.toString("base64"));
|
||||
};
|
||||
await one.evaluate((box) => { for (const a of box.getAnimations({ subtree: true })) { a.pause(); a.currentTime = 0; } });
|
||||
const pulsing = await centre();
|
||||
await one.evaluate((box) => { for (const a of box.getAnimations({ subtree: true })) a.cancel(); });
|
||||
const still = await centre();
|
||||
const gap = Math.max(...pulsing.map((v, k) => Math.abs(v - still[k])));
|
||||
assert.ok(gap <= 2, `${name}: the pulse tints the dot it rings (${still} → ${pulsing})`);
|
||||
}
|
||||
// the dots keep their places when they start to pulse
|
||||
const at = () => p.evaluate((sels) => sels.map((s, i) => { const r = document.querySelectorAll(".one")[i].querySelector(s).getBoundingClientRect(); return [r.left, r.top, r.width]; }), DOTS.map((d) => d[2]));
|
||||
const pulsing = await at();
|
||||
await p.evaluate(() => { for (const e of document.querySelectorAll(".now, .on, .wait")) e.classList.remove("now", "on", "wait"); });
|
||||
assert.deepEqual(await at(), pulsing, "a dot moved when it started to pulse");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user