masking: the flow's dots, scan and Live dot stop moving once played (#3185)

The Masking page never came to rest. Each dot in its agents-to-providers
flow was an SVG animateMotion with repeatCount "indefinite", the scan
mark on the middle line ran forever, and the Live dot pulsed forever.
The SMIL dots alone made Chromium lay the page out ~700 times a second
(6,965 layouts and 2,282 style recalcs in 10s, read with CDP
Performance.getMetrics). Removing just those 22 elements took it to 0.

Now each dot goes round twice when the flow is drawn, and the scan mark
plays twice. The flow is drawn again only when the numbers change. The
Live dot pulses once each time the list is drawn again, which happens on
each 15s read. Reduced motion is unchanged: still no motion at all.

Measured on a sandbox `magpie app` (origin/main, sandbox HOME, real
deepseek provider, the real masking log copied in: 19,657 values over
577 requests). The Masking page was loaded in Playwright 1.62.0, and only
that browser's own processes were sampled with proc_pid_rusage, 20s per
sample:
- WebKit, before: 180 wakeups/s, 2.8% CPU, 56 mW.
  After: 37/s and 9.7 mW while the motion plays out (8-28s), then
  10.8/s, 0.1% CPU, 1.4 mW.
- Chromium, before: 96-98/s, 17% CPU, 537-543 mW.
  After: 40/s, 2.0% CPU, 57 mW while the motion plays out, then
  18.5/s, 0.5% CPU, 10 mW.
- The other pages at rest: 12-30/s and 1.6-7.7 mW in WebKit.

Test: masking-records' new "the masking page's motion ends" (chromium
and webkit, 1100px and 640px). It moves the SVG clock on an hour and
asks Chromium whether any dot is still in an interval. In both engines
it checks that no SMIL element is set to repeat for good and that no
CSS animation has an infinite end. All 4 cases are red on the old
page.js/redact.css and green on the new ones.

Run at this tree:
- masking-records, held-animations and i18n-keys: 68/68.
- account-mask-sessions, account-mask, mask-actions, mask-emails,
  provider-unmasked and redact-*: 172/172.
- go test -timeout 45m ./internal/gui: ok.
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gui: ok.
- gofmt: clean.

Other states measured, with no change made:
- Go main process at rest with the window open: 25/s, 7 mW.
- Streaming 3 deepseek-flash replies (2,450 SSE events in 20s):
  275/s, 3.5% CPU, 107 mW, about 2 wakeups per event.

Not tried: the window hidden and the tray panel open; the
WKWebView in the real app window on Masking (measured in Playwright's
WebKit instead); the full GUI suite.
This commit is contained in:
yetone
2026-10-25 20:33:33 +08:00
parent 41b0445ccf
commit 4b3bdbe28c
3 changed files with 38 additions and 4 deletions
+3 -1
View File
@@ -317,7 +317,9 @@ function maskFlow(sum, move) {
if (q === ks[i] >> 1 && !still) for (let k = 0, dots = 1 + Math.round(2 * r.n / max); k < dots; k++) {
const dur = 1.7 + i * .5, begin = (out ? dur : 0) + k * 2 * dur / dots + "s";
const z = out ? 1.8 : 1.7, dot = add("rect", { x: -z, y: -z, width: 2 * z, height: 2 * z, rx: out ? .6 : z, class: "mo-dot" + (out ? " out" : "") });
const a = { dur: dur + "s", begin, repeatCount: "indefinite" };
// twice round when drawn, not forever: an endless motion lays the
// page out each frame, ~16% of a core while it sits open (#3185)
const a = { dur: dur + "s", begin, repeatCount: 2 };
add("animateMotion", { path: d, ...a }, dot);
add("animate", { attributeName: "opacity", values: "0;1;1;0", keyTimes: "0;.1;.85;1", ...a }, dot);
}
@@ -65,7 +65,7 @@
.mo-th.one { stroke-width: .9; }
.mo-mem { stroke: var(--accent); stroke-opacity: .55; stroke-width: 1; }
.mo-tick { stroke: var(--accent); stroke-opacity: .35; stroke-width: .6; }
.mo-scan { fill: var(--accent); opacity: 0; animation: mo-scan 5.5s cubic-bezier(.45, 0, .55, 1) infinite; }
.mo-scan { fill: var(--accent); opacity: 0; animation: mo-scan 5.5s cubic-bezier(.45, 0, .55, 1) 2; }
@keyframes mo-scan { 0% { transform: translateY(0); opacity: 0; } 15%, 85% { opacity: 1; } 100% { transform: translateY(var(--h)); opacity: 0; } }
.mo-dot { fill: var(--fg); opacity: 0; }
.mo-dot.out { fill: var(--accent); }
@@ -88,7 +88,7 @@
.msk-list { margin-top: 14px; }
.msk-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.msk-live { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.msk-live i { width: 6px; height: 6px; border-radius: 50%; background: var(--green, var(--accent)); animation: msk-live 2.4s ease-in-out infinite; }
.msk-live i { width: 6px; height: 6px; border-radius: 50%; background: var(--green, var(--accent)); animation: msk-live 2.4s ease-in-out; }
@keyframes msk-live { 50% { opacity: .35; } }
.msk-facets { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.msk-facet { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--fg-2); font: inherit; font-size: 12px; cursor: default; white-space: nowrap; }
+33 -1
View File
@@ -125,7 +125,7 @@ function serve(lang, sum, asked, opts = {}) {
async function open(engine, lang, width, sum, where, opts) {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: "reduce" })).newPage();
const page = await (await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: opts?.motion ? "no-preference" : "reduce" })).newPage();
page.setDefaultTimeout(8000);
const errors = [], asked = [];
page.on("pageerror", (e) => errors.push(e.message));
@@ -166,6 +166,38 @@ async function stillClick(page, loc) {
assert.deepEqual(await scrolled(page), before, "no click moved the page");
}
// The page comes to rest while it sits open (#3185): the flow's dots, its
// scan mark and the Live dot each play a few times when drawn. Endless,
// the dots (SMIL) laid the page out ~700 times a second in Chromium, 16%
// of a core and ~0.5W; in WebKit 180 wakeups a second. SMIL's clock is
// moved on and each CSS animation's end is read, so nothing waits.
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const width of [1100, 640]) {
test(`${engine} ${width}px: the masking page's motion ends`, async (t) => {
const { browser, page, errors } = await open(engine, "en", width, summary, "", { motion: true });
t.after(() => browser.close());
const card = page.locator("#maskCard");
await card.locator(".mo-flow .mo-dot").first().waitFor({ state: "attached" });
await page.locator("#maskList .msk-live i").waitFor({ state: "attached" });
const rest = await page.evaluate(() => {
const smil = [...document.querySelectorAll("#view-masking animate, #view-masking animateMotion")];
for (const svg of new Set(smil.map((a) => a.ownerSVGElement))) svg.setCurrentTime(3600);
// WebKit keeps an ended one's start time, so only Chromium is asked
// the clock; both are asked each one's own timing
const on = smil.filter((a) => { try { a.getStartTime(); return true; } catch { return false; } }).length;
const forever = smil.filter((a) => ["repeatCount", "repeatDur", "dur", "end"].some((k) => a.getAttribute(k) === "indefinite") || !(+a.getAttribute("repeatCount") > 0)).length;
const endless = document.getAnimations().filter((a) => a.effect?.getComputedTiming().endTime === Infinity).map((a) => a.animationName || a.id || "?");
return { smil: smil.length, on, forever, endless };
});
assert(rest.smil > 0, "the flow moves when drawn");
assert.equal(rest.forever, 0, "a dot set to go round for good");
if (engine === "chromium") assert.equal(rest.on, 0, "an hour on, a dot still goes round");
assert.deepEqual(rest.endless, [], "an animation that never ends");
assert.deepEqual(errors, []);
});
}
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 640]) {