Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

routing: a long wire is drawn as pieces of its curve, which WebKit dashes cheaply (#3164)

yetoned42d27012bc7
diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js
index f43a32399..3e025651e 100644
--- a/internal/gui/assets/plugins/routing/client.js
+++ b/internal/gui/assets/plugins/routing/client.js
@@ -1425,6 +1425,24 @@ function routingPage(part) {
}
function show(c) { capLo = !!c.lo; cap.textContent = c.s; cap.classList.remove("in"); void cap.offsetWidth; cap.classList.add("in"); capAt = performance.now(); }
+ // curve is a wire's S from (x0, y0) to (x3, y3), its bends at mx: one
+ // cubic, cut into exact pieces of it about 1000 px tall (the middle ones
+ // up to 1.5 times that). WebKit dashes a cubic at a cost that grows faster
+ // than its length, and a key's fold hundreds of rows from magpie (#3164)
+ // had its flowing wire as one 18,000 px cubic: ~75 ms of each frame. The
+ // pieces trace the same curve.
+ function curve(x0, y0, mx, x3, y3) {
+ let a = [x0, y0], b = [mx, y0], c = [mx, y3];
+ const d = [x3, y3], lerp = (p, q, t) => [p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t];
+ let s = `M${x0} ${y0}`;
+ for (let n = Math.min(64, Math.ceil(Math.abs(y3 - y0) / 1000)); n > 1; n--) {
+ const t = 1 / n, ab = lerp(a, b, t), bc = lerp(b, c, t), cd = lerp(c, d, t), abc = lerp(ab, bc, t), bcd = lerp(bc, cd, t), m = lerp(abc, bcd, t);
+ s += ` C${ab[0]} ${ab[1]} ${abc[0]} ${abc[1]} ${m[0]} ${m[1]}`;
+ a = m; b = bcd; c = cd;
+ }
+ return s + ` C${b[0]} ${b[1]} ${c[0]} ${c[1]} ${x3} ${y3}`;
+ }
+
function layout() {
const r = stage.getBoundingClientRect();
if (!r.width) return;
@@ -1440,12 +1458,12 @@ function routingPage(part) {
const h = b(hub), low = b(srcs).b;
for (const a of agents.values()) {
const s = b(a.node), mx = (s.r + h.l) / 2;
- sets.push([a.wire, h.l > s.r ? `M${s.r} ${s.cy} C${mx} ${s.cy} ${mx} ${h.cy} ${h.l} ${h.cy}` : `M${s.cx} ${s.b} L${h.cx} ${h.t}`]);
+ sets.push([a.wire, h.l > s.r ? curve(s.r, s.cy, mx, h.l, h.cy) : `M${s.cx} ${s.b} L${h.cx} ${h.t}`]);
}
const fromHub = (a) => {
if (a.l > h.r) {
const mx = (h.r + a.l) / 2;
- return `M${h.r} ${h.cy} C${mx} ${h.cy} ${mx} ${a.cy} ${a.l} ${a.cy}`;
+ return curve(h.r, h.cy, mx, a.l, a.cy);
}
// the accounts sit under magpie: a lane down their left, from below the agents too
const x = a.l - 12, y = Math.max(h.b, low - 8);
diff --git a/internal/gui/tests/routing-many-keys.test.cjs b/internal/gui/tests/routing-many-keys.test.cjs
index baa87db6d..557138ed9 100644
--- a/internal/gui/tests/routing-many-keys.test.cjs
+++ b/internal/gui/tests/routing-many-keys.test.cjs
@@ -11,7 +11,10 @@
// another serve a group while requests come, folded and opened, and what
// the page does is counted: no key lookup through a whole list, times
// parsed a bounded number of times, and no box read after a wire drawn
-// in the same pass. English, Chinese and German; the API is faked here.
+// in the same pass. And no wire is one cubic thousands of pixels tall: WebKit
+// dashes a cubic at a cost that grows faster than its length, and the
+// flowing wire to a fold hundreds of rows from magpie took ~75 ms of each
+// frame. English, Chinese and German; the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -113,7 +116,26 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForFunction(() => document.querySelectorAll("#view-routing .rt-accts > li:not(.rt-fold)").length >= 800);
const opened = await look();
clearInterval(pump);
- t.diagnostic(`folded ${JSON.stringify(folded)}, open ${JSON.stringify(opened)}`);
+ // the tallest wire, and the tallest cubic any wire is drawn with
+ const tall = await page.evaluate(() => {
+ let wire = 0, cubic = 0;
+ for (const p of document.querySelectorAll("#view-routing .rt-wires path[d]")) {
+ const n = (p.getAttribute("d").match(/-?[\d.]+(?:e-?\d+)?|[A-Za-z]/g) || []);
+ let cmd = "", ys = [], y = 0;
+ for (let i = 0; i < n.length;) {
+ if (/[A-Za-z]/.test(n[i])) { cmd = n[i++]; continue; }
+ const k = { M: 2, L: 2, Q: 4, C: 6 }[cmd] || 2, a = n.slice(i, i + k).map(Number);
+ i += k;
+ const pts = [y, ...a.filter((_, j) => j % 2)];
+ if (cmd === "C") cubic = Math.max(cubic, Math.max(...pts) - Math.min(...pts));
+ y = pts[pts.length - 1];
+ ys.push(...pts);
+ }
+ wire = Math.max(wire, Math.max(...ys) - Math.min(...ys));
+ }
+ return { wire: Math.round(wire), cubic: Math.round(cubic) };
+ });
+ t.diagnostic(`folded ${JSON.stringify(folded)}, open ${JSON.stringify(opened)}, wires ${JSON.stringify(tall)}`);
for (const [name, n] of [["folded", folded], ["open", opened]]) {
// a key's place is looked up in an index of its provider's list:
// before, a sort of 800 keys looked through the 500 for each of
@@ -128,6 +150,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(n.thrash < 400, `${name}: the stage laid out again ${n.thrash} times for a wire drawn, in 3s`);
}
assert(opened.boxes > 800, `the open stage was laid out (${opened.boxes} boxes read)`);
+ // a wire to a fold far from magpie runs thousands of pixels, in
+ // pieces of its curve: before, it was one cubic as tall as itself
+ assert(tall.wire > 5000, `the tallest wire is ${tall.wire}px`);
+ assert(tall.cubic <= 2000, `a wire is drawn with a cubic ${tall.cubic}px tall`);
assert.deepEqual(errors, []);
});
}