gui: Discover's long-list hook moves into plugingrid.js, and the core budget carries the rest

TestCoreScriptBudget has been red on main since 5a0e0378c (06:00): the
core's scripts were 1,265,848 bytes against 1,265,544. 5a0e0378c added
344 bytes of code to plugins.js, and its body says the budget passed at
7583ed65c, but at 7583ed65c the core had only 40 bytes of room. CI's
first full run after it (e9e63c6d7, run 43323956017) went red on ubuntu
and macOS with those numbers.

The redraw that followed the import, and the threshold, now live in
plugingrid.js: pmVirtualGrids(page, card, body, draw) draws Discover's
body again from a microtask, once plugins.js holds what it returned, when
a list of VMIN cards or more was drawn whole before the import came. It
returns min, so plugins.js reads the threshold from it. plugins.js keeps
only the import, cardGrid and the three now() calls: 136 bytes out. The
budget carries the other 168, with why in its comment. The comment also
had ee1553913's "+1,112 for Codex's Open button" twice; the budget was
raised by 1,112 once (1,264,432 to 1,265,544), so one copy goes.

Run on mote at this tree (origin/main 390dd407b plus this), mote-run:
- go vet ./internal/gui; go test -run 'TestCoreScriptBudget|TestAppScript'
  ./internal/gui: ok. gofmt -l: nothing. node --check on both files.
- plugin-discover-virtual 22 of 22, plugin-market 6, plugin-kinds-discover
  22, plugins-more-discover 6, plugin-progressive 6, i18n-keys 4: all pass.
- old-webkit: 2 reds, the known ones (headerpresets.js #6030, :has()
  #5919), as 5a0e0378c recorded.
- Recomputed the budget's measure at 7583ed65c, 5a0e0378c and this tree
  with a copy of codeBytes: 1,265,504, 1,265,848, 1,265,712.

Broken by hand: with the microtask redraw taken out,
plugin-discover-virtual still passes 22 of 22, so the "drawn whole before
the import" redraw has no test, before this change and after it.

Not tried: the real app; a long list drawn before plugingrid.js arrives.
This commit is contained in:
yetone
2026-11-13 08:18:10 +08:00
parent 390dd407b9
commit 5a44051eb5
3 changed files with 15 additions and 13 deletions
+8 -4
View File
@@ -3,10 +3,14 @@
// with all of them. The grid keeps the whole list's height in its padding
// above and below what it shows, and the rows follow the scroll; a card
// with focus is kept. plugins.js imports this when its page is first drawn,
// so it weighs nothing on the core; a list shorter than its VMIN is drawn
// whole there.
window.pmVirtualGrids = function (page, card) {
// so it weighs nothing on the core; a list shorter than VMIN is drawn
// whole there. body() is Discover's body, and draw() draws it again.
window.pmVirtualGrids = function (page, card, body, draw) {
const VMIN = 48; // the shortest list drawn in part
const VMORE = 700; // px drawn past each edge of the view
// a long list drawn whole before this came is drawn again, once the
// caller holds what this returns
queueMicrotask(() => { if (body()?.querySelector(".pm-grid:not(.pm-virtual) > .pm-card:nth-child(" + VMIN + ")")) draw(); });
const vgrids = new Set();
let vrowH = 172, vcols = 3; // a row's height and the columns, as last measured
function grid(g, list) {
@@ -106,5 +110,5 @@ window.pmVirtualGrids = function (page, card) {
const vsoon = () => { if (vgrids.size && !vframe) vframe = requestAnimationFrame(vnow); };
page.addEventListener("scroll", vsoon, { passive: true });
if (window.ResizeObserver) new ResizeObserver(vsoon).observe(page);
return { grid, now: vnow };
return { grid, now: vnow, min: VMIN };
};
+6 -8
View File
@@ -647,16 +647,14 @@
// a long list draws only the rows near the view (plugingrid.js); until
// that has come, and for a short list, every card is drawn
const VMIN = 48;
let vg = null;
const vload = () => vload.p = vload.p || import("./plugingrid.js").then(() => { vg = pmVirtualGrids(page, card); if (body?.querySelector(".pm-grid:not(.pm-virtual) > .pm-card:nth-child(" + VMIN + ")")) drawBody(); }, () => {});
let vg;
const vload = () => vload.p = vload.p || import("./plugingrid.js").then(() => vg = pmVirtualGrids(page, card, () => body, drawBody), () => {});
function cardGrid(list) {
const g = el("div", "pm-grid");
if (list.length >= VMIN && vg) return vg.grid(g, list);
if (list.length >= vg?.min) return vg.grid(g, list);
for (const l of list) g.append(card(l));
return g;
}
const vnow = () => vg?.now();
// Discover is one market (#owner, 11-09): every plugin, whoever wrote
// it (magpie's community, another author on npm, a repository its
@@ -1013,7 +1011,7 @@
replaceKeeping(page, [head(), body]);
drawBody();
page.scrollTop = scroll;
vnow();
vg?.now();
}
function drawBody() {
@@ -1048,7 +1046,7 @@
import("./registry.js").then(() => pmRegistry(regBox, mine, askNPM), statusTErr);
}
replaceKeeping(body, out);
vnow();
vg?.now();
if (agentsFor && body.querySelector(".pm-agents")) {
// after the view is put back where the reader was, as showing it
// does; the section then is the one drawn last (npm's answers draw
@@ -1081,7 +1079,7 @@
}
out.push(box);
replaceKeeping(body, out);
vnow();
vg?.now();
}
// what a plugin is to the reader, and how one is written, under the list
+1 -1
View File
@@ -18,7 +18,7 @@ import (
// `git log -L` of this file.
const (
appScriptBudget = 1_086_267 // app.js: 1,080,614 at 8016205e3, with the 5,653 of room it had
coreScriptBudget = 1_265_544 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations; +113 for withScheme, the one rule every typed address goes through (eachg0 on X), cut to the shortest form that keeps it whole; +10 for the kept whole's tooltip (Musikrv77852 on X), the past-cycle line reused for it, no page left to move it to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to
coreScriptBudget = 1_265_712 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations; +113 for withScheme, the one rule every typed address goes through (eachg0 on X), cut to the shortest form that keeps it whole; +10 for the kept whole's tooltip (Musikrv77852 on X), the past-cycle line reused for it, no page left to move it to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to; +168 for Discover's long lists drawn in part (the owner, 11-13), after the rest of its hook moved into plugingrid.js, imported when Plugins first draws
)
// codeBytes is how many bytes of b are code: its blank lines, its lines