fitQuota stacks each window's counts and gives side-by-side names one
height. It ran group by group: clear the names' min-height, then read
their offsetTop. Every read after a write lays the card out again, so
one Usage render with N accounts in full laid the card out N times,
O(N²). With 600 accounts at 520px wide and the names wrapping (a long
window name), one render held WebKit's WebContent at 100% CPU: 1.7-2.3s
of script and 10-13s to the second frame after it. Chromium took
1.2-1.4s.
fitQuota now takes every group. It reads all the sizes first, then
writes the classes and clears the heights. It reads each name's row and
height in one pass, then sets the heights. packUsage's heights() passes
the card's groups in one call; the ResizeObserver path already passed a
set.
Probe (600 accounts, all open, W=520, wrapped names), on mote:
WebKit: 0.5s sync, 0.7s to two frames (was 1.7-2.3s, 10-13s)
Chromium: 0.45s (was 1.2-1.4s)
Wide layout, both engines: 0.3-0.4s before and after.
Scrolling 600 accounts was smooth before and after (2 frames ~30ms).
Test: quota-fit-batched.test.cjs counts the layouts forced in one
render: a read of a layout getter while MutationObserver records are
pending. The count must be the same at 160 accounts as at 40 (+4 room
for a frame's observer). It also checks that every group was drawn, the
names' heights were written, and each group was evened. Chromium and
WebKit, en/zh/zh-TW/ja/de, 10/10 green.
Broken by hand: the test pointed at HEAD's app.js (MAGPIE_FIT_ASSETS)
is red 10/10: 243 forced layouts at 40 accounts, 963 at 160, both
engines.
Run (mote, load ~30; first at base 40cfae5d3 + this change):
- 161 GUI files that touch quota/usage/panel, both engines, every
language they cover: 2832 tests, 34 red in 9 files.
- Those 9 files again, on this change and on base 40cfae5d3 alone: 25
red with the change, 30 on base. Every red on the change is also red
on base except provider-mask, which times out in a different language
each run on both trees (#5109).
- The reds on base are filed: codex-auto-reset webkit de (#4790),
mobile-web (#3952, #5013), tray-cell-click (#5215), usage-fold
'most on one screen' (#4790, #3415), and panel-fold (#5796, filed now).
- i18n-keys 'a plugin's words are its own' is red (#5327, #5332,
#5426, #5482).
- At the pushed head (this change on origin/main c056b7c8c):
TestCoreScriptBudget ok. quota-fit-batched 10/10, and usage-agents-hide,
usage-compact-counts, usage-fold, usage-ledger and usage-ledger-search
run beside it: 32 red, the same 32 as at c056b7c8c alone
(usage-agents-hide #2276#3414, usage-ledger Requests #5048, usage-fold
#4790#3415).
Not tried: the real app with 600 real accounts. The fixture's accounts
are Claude windows with one long name. Another layer is not changed:
the first layout after the rebuild, resetClock's Intl formatters, and
building the DOM, ~45ms each at 600 accounts.