gui tests: routing-busy-frames counts paths measured again for the same d, not lengths against frames (#3557)

The bar was path lengths < 8 × frames drawn. The lengths follow the
paths the flights and the moving rows make (~1,800 in the 3s), not the
frames, so a busy machine that drew 228 frames instead of ~300 went red
with the page doing just what it should.

What the test is about is that a path is measured once for each d it
has. The page's getTotalLength and getPointAtLength are now wrapped to
remember the d each path was last measured at: a length measured again
for the same d, or a point again at the same distance along the same d,
is counted. The bars: lengths again ≤ 1/20 of lengths, points again ≤ 2
for each d measured (a wire's two ends are asked for by its tips and
among its points). Neither depends on the frame count.

Run at this head (frames3557 worktree on origin/main 8299409e4):
- routing-busy-frames.test.cjs: 6/6 pass, chromium and webkit, en/zh/de:
  ~1,750 lengths, 0 again; ~5,800 points, ~320 again (bar ~3,500).
- Broken by hand: measure() measuring every call: 6/6 red (9,807 of
  11,574 lengths again). The point cache alone off: webkit 3/3 red
  (6,892 points again against a bar of 3,534).

Not tried: the file under the whole GUI suite at load ~40 where #3557
was seen.
This commit is contained in:
yetone
2026-10-26 00:14:31 +08:00
parent 8299409e44
commit 81a58d2f35
@@ -57,10 +57,28 @@ function serve(lang, feed) {
// counts of what the page measures, and of the frames it draws
const init = () => {
const n = window.__n = { len: 0, pt: 0, fmt: 0, frames: 0 };
const n = window.__n = { len: 0, pt: 0, lenAgain: 0, ptAgain: 0, fmt: 0, frames: 0 };
const P = SVGGeometryElement.prototype, len = P.getTotalLength, pt = P.getPointAtLength, fmt = Number.prototype.toLocaleString;
P.getTotalLength = function () { n.len++; return len.call(this); };
P.getPointAtLength = function (d) { n.pt++; return pt.call(this, d); };
// what each path was measured at last, by its d: a length measured again
// for the d it had then, or a point again along the same d, is one the
// page measured before and asked for anew
const lenAt = new WeakMap(), ptAt = new WeakMap();
P.getTotalLength = function () {
n.len++;
const d = this.getAttribute("d");
if (d && lenAt.get(this) === d) n.lenAgain++;
lenAt.set(this, d);
return len.call(this);
};
P.getPointAtLength = function (s) {
n.pt++;
const d = this.getAttribute("d");
let m = ptAt.get(this);
if (!m || m.d !== d) ptAt.set(this, m = { d, at: new Set() });
if (d && m.at.has(s)) n.ptAgain++;
m.at.add(s);
return pt.call(this, s);
};
Number.prototype.toLocaleString = function (...a) { n.fmt++; return fmt.apply(this, a); };
const raf = window.requestAnimationFrame.bind(window);
window.requestAnimationFrame = (cb) => raf((ts) => { n.frames++; cb(ts); });
@@ -97,14 +115,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForTimeout(3000);
const after = await page.evaluate(() => ({ ...window.__n }));
clearInterval(pump);
const frames = after.frames - before.frames, len = after.len - before.len, pt = after.pt - before.pt, fmt = after.fmt - before.fmt;
t.diagnostic(`${frames} frames, ${len} lengths, ${pt} points, ${fmt} formats`);
const [frames, len, pt, lenAgain, ptAgain, fmt] = ["frames", "len", "pt", "lenAgain", "ptAgain", "fmt"].map((k) => after[k] - before[k]);
t.diagnostic(`${frames} frames, ${len} lengths (${lenAgain} again), ${pt} points (${ptAgain} again), ${fmt} formats`);
assert(frames > 20, `only ${frames} frames drawn`);
// a path is measured when it is new or moved, not again for every
// flight on it every frame: ~15 a frame before, ~4 now (the wires
// the stage moves — rows sliding to their new places, an agent
// ticking — are measured again as they move)
assert(len < 8 * frames, `${len} path lengths measured over ${frames} frames`);
// flight on it every frame (the wires the stage moves — rows sliding
// to their new places, an agent ticking — are measured again as they
// move, so they are new d's). Counted against the d's measured, not
// the frames: a busy machine draws fewer frames while the flights'
// paths stay as many, and the bar by frames went red there (#3557).
assert(lenAgain <= len / 20, `${lenAgain} of ${len} path lengths measured again for a d already measured`);
// a wire's two ends are asked for once by its tips and once among
// the points along it: two a d at most, never one a frame
assert(ptAgain <= 2 * len, `${ptAgain} of ${pt} points measured again along the ${len} d's measured`);
// the rows' numbers come from one formatter, not one per number
assert(fmt < 200, `${fmt} numbers formatted one formatter each over ${frames} frames`);
// and they still read in the page's language