From 9fc382e66d693f8cdf0cecf7a0f92f29995c83de Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 26 Oct 2026 02:00:41 +0800 Subject: [PATCH] routing: a key off screen is not laid out or painted, so hundreds of open keys keep WebKit's frames (#3164) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With a group's 500 and 300 keys both open, WebKit drew ~40 frames a second on the Routing page: hiding the keys below row 60 alone gave back ~100 frames in 10s, so it painted every row again on each frame a magpie flew. Chromium was at 60 already. A key row now has content-visibility: auto, so one out of sight is skipped. Its height while skipped is contain-intrinsic-size: auto var(--rt-row): the last height it was drawn at, or, never drawn, the content height of a key drawn now, which layout() reads with the boxes it reads already and sets a frame later (set in the stage's own ResizeObserver, WebKit reported a loop). Rows keep their heights, so the wires to them and the list's scroll height are as before. A row a 429 hit (.hit) is drawn whole: its tag stands over its top edge, which the paint containment would cut. A WebKit without content-visibility or checkVisibility draws every row as before. Run at this head (rebased on origin/main 5214d5114): - routing-many-keys.test.cjs, new checks: a key in sight is drawn, the last of 800 is not, and every key is one height. Chromium and WebKit, en/zh/de: 6/6. On the old routing.css and client.js: 0/6 (the last key drawn); with this routing.css but the old client.js: 0/6 (keys 61 or 62px drawn, 58px not). - every routing*.test.cjs and panel-routing*.test.cjs (112 files, --test-concurrency=6, load ~27): 1418 tests, 1362 pass, 56 fail. Run alone at origin/main 5214d5114 and at this head: routing-kind 4/0, routing-keys-fold 32/0 and routing-rule-drag 10/0 on both (their reds were the full run's); routing-steady 0/2 on both (#3412); routing-rule-remove 9/11 at main, 12/8 here (#3094, #3096). The rest are the files 3173440ca compared on main: routing-intent-entry (#3408), -manual (#3409), -pause (#3410), -rule-effort (#3411), -live-patch (#3637). - go test ./internal/gui/ (budgets included): ok. - Sandbox (sbh-paint: providers of 500 and 300 keys on a fake upstream, a request every 0.3s, both groups open, Playwright WebKit 1280x900, 10s, the served client.js and routing.css swapped four times): frames 367/391/410/412 -> 444/469/472/533, frames over 50ms 3/4/3/4 -> 2/1/2/0. Off-screen row heights at 1280 and 700px wide measured the same as uncontained (38 and 61). Tried and left out: the flowing wire's dashes on an SVG layer of its own (no change past the noise, ~±30 frames); will-change on the wires and the sky (none). Stopping the live wire's dash animation gives ~+40 frames more, but it is what says a request is with that key (#2386). Not tried: the macOS app's own WKWebView window, WebKitGTK, a real upstream. Rebased on origin/main 385ce789e (a sidebar change only) and run again there: routing-many-keys and routing-row-swap 8 pass, 0 fail. --- internal/gui/assets/plugins/routing/client.js | 8 ++++++++ internal/gui/assets/plugins/routing/routing.css | 6 ++++++ internal/gui/tests/routing-many-keys.test.cjs | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 1ca0f115b..92c57b566 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -1456,6 +1456,11 @@ function routingPage(part) { return v; }; const h = b(hub), low = b(srcs).b; + // a key off screen is not drawn, and its content is as tall as a drawn + // key's (routing.css, #3164) + let row = list.firstElementChild; + while (row && (row.matches(".rt-fold, .rt-sub, .idle") || !row.firstElementChild?.checkVisibility?.({ contentVisibilityAuto: true }))) row = row.nextElementSibling; + const pad = row && getComputedStyle(row), rowH = row && Math.round((b(row).b - b(row).t - parseFloat(pad.paddingTop) - parseFloat(pad.paddingBottom) - parseFloat(pad.borderTopWidth) - parseFloat(pad.borderBottomWidth)) * 100) / 100; 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 ? curve(s.r, s.cy, mx, h.l, h.cy) : `M${s.cx} ${s.b} L${h.cx} ${h.t}`]); @@ -1491,6 +1496,9 @@ function routingPage(part) { const up = f?.open ? f : row.up && subs.get(row.up), a = b(row.li); sets.push([row.wire, up ? fromSub(up, a) : fromHub(a)]); } + // set after this frame: the keys not drawn changing size resize the + // stage, which in its own ResizeObserver WebKit reports as a loop + if (rowH && list.style.getPropertyValue("--rt-row") !== rowH + "px") requestAnimationFrame(() => list.style.setProperty("--rt-row", rowH + "px")); wires.setAttribute("viewBox", `0 0 ${r.width} ${r.height}`); sky.setAttribute("viewBox", `0 0 ${r.width} ${r.height}`); for (const [p, d] of sets) { diff --git a/internal/gui/assets/plugins/routing/routing.css b/internal/gui/assets/plugins/routing/routing.css index ab35f4d77..4e7d5b430 100644 --- a/internal/gui/assets/plugins/routing/routing.css +++ b/internal/gui/assets/plugins/routing/routing.css @@ -53,6 +53,12 @@ .rt-accts { position: relative; z-index: 1; list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; min-width: 0; } .rt-accts li { position: relative; display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; column-gap: 10px; row-gap: 6px; padding: 9px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 13px; transition: opacity .3s, border-color .3s, transform .5s cubic-bezier(.2, .8, .2, 1); } .rt-accts li { margin-left: calc(var(--depth, 0) * 18px); } +/* a key off screen is not laid out or painted (#3164): with hundreds of + keys open, WebKit painted every row again on each frame a magpie flew. + One not drawn yet is as tall as a key drawn is (--rt-row, client.js's + layout). A row a 429 hit keeps its tag up over its top edge, which this + would cut, so it is drawn whole */ +.rt-accts li:not(.hit) { content-visibility: auto; contain-intrinsic-size: auto var(--rt-row, 38px); } /* a group in the group: a heading its models hang from, set in under it */ .rt-accts li.rt-sub { display: flex; align-items: center; gap: 7px; padding: 5px 10px; font-size: 12px; color: var(--muted); background: var(--card-2); border-style: dashed; } .rt-accts li.rt-sub.on { border-style: solid; border-color: var(--fg-2); color: var(--fg); } diff --git a/internal/gui/tests/routing-many-keys.test.cjs b/internal/gui/tests/routing-many-keys.test.cjs index 557138ed9..d7bbfb5a1 100644 --- a/internal/gui/tests/routing-many-keys.test.cjs +++ b/internal/gui/tests/routing-many-keys.test.cjs @@ -135,7 +135,21 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", } return { wire: Math.round(wire), cubic: Math.round(cubic) }; }); - t.diagnostic(`folded ${JSON.stringify(folded)}, open ${JSON.stringify(opened)}, wires ${JSON.stringify(tall)}`); + // a key far below the fold of the window is not drawn, and is as tall + // as the keys drawn: drawn, WebKit painted all 800 again on each frame + // a magpie flew, ~40 frames a second + const rows = await page.evaluate(() => new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(() => { + const keys = [...document.querySelectorAll("#view-routing .rt-accts > li:not(.rt-fold):not(.rt-sub):not(.idle):not(.hit)")]; + const drawn = (li) => li.firstElementChild.checkVisibility({ contentVisibilityAuto: true }); + const mid = (li) => { const r = li.getBoundingClientRect(); return Math.abs((r.top + r.bottom) / 2 - innerHeight / 2); }; + const seen = keys.reduce((a, li) => (mid(li) < mid(a) ? li : a)); + const h = (li) => Math.round(li.getBoundingClientRect().height); + done({ shown: mid(seen) < innerHeight / 2 && drawn(seen), last: drawn(keys[keys.length - 1]), heights: [...new Set(keys.map(h))] }); + })))); + t.diagnostic(`folded ${JSON.stringify(folded)}, open ${JSON.stringify(opened)}, wires ${JSON.stringify(tall)}, rows ${JSON.stringify(rows)}`); + assert.equal(rows.shown, true, "a key in sight is drawn"); + assert.equal(rows.last, false, "the last of 800 keys, out of sight, is not drawn"); + assert.equal(rows.heights.length, 1, `keys drawn and not are one height: ${rows.heights}`); 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