Repository navigation
perf(list): bound the results list by DOM budget, not virtualization - #125
Merged
Merged
Conversation
Closes #98 The ticket asked for a virtualized results list, with a lower `MAX_REVEAL` as the sanctioned fallback. Profiling the real list inside the vaul drawer at 6x CPU throttle inverted its premise, so the fallback is what ships. Over an identical 40px-per-frame scroll: 331 rows / 7,331 nodes, fully revealed: median 8.3ms, p95 17.4ms, 0/100 frames >32ms 50 rows / 1,079 nodes, actively paging: median 38.4ms, p95 175ms, 71/100 frames >32ms Six times the DOM scrolled better. Rendering a card costs; owning one does not. The janky frames were the `useTransition` reveal building the next page and did not coincide with the commit that grew the row count (1 of 71). A windowing virtualizer re-renders cards as they enter the viewport, so it would pay that cost repeatedly on every scroll rather than once per row — a `content-visibility: auto` A/B run alongside showed exactly that shape, doubling p95 (36->59ms) and quintupling the worst frame (61->307ms). `@tanstack/react-virtual` was installed, measured against, and removed; package.json and the lockfile are unchanged. So `MAX_REVEAL` drops from 1,000 to 400 rows for the reason that survived measurement — DOM hygiene inside a host page we don't own, ~22,000 nodes down to ~8,900 — not smoothness. 400 sits just above the 331-row depth verified smooth, making it a measured bound rather than a guessed one, and 16 pages is ~15 deliberate presses past the first: far beyond any reading depth, and it never touches the auto-paged nearby segment. A new ratchet test pins the ceiling to that node budget. Every other test here spells the bound as `MAX_REVEAL`, so all of them pass just as happily at a million — which is how this could be raised back with the gate green. Verified in the browser, all unchanged: auto-paging within the nearby segment (25->63 rows by scrolling alone), the distant boundary holding without a press (63->63 across six more scrolls) and its label persisting, never `disabled`, reveal position surviving an event open and back (88 rows), Tab walking rows 6->17 without focus ever reaching <body>, and hover prefetch still firing on dwell while the #97 gate suppressed a 14-row sweep to one request. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A comment explaining the rows/count divergence named "1000 rows", which lowering MAX_REVEAL had just made wrong. Spelled as the constant so the line tracks the ceiling wherever it moves next. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Findings from the /code-review pass, all in what the change CLAIMED rather than what it did. The docblock said the ceiling "never touches the auto-paged nearby segment". That is false, and it is the sharp edge that matters: when the nearby segment alone fills MAX_REVEAL, `more` goes null and the whole distant segment becomes unreachable for that search — announced only in the sr-only live region. Confirmed live: `rows: 400, more: null, next: null, total: 460`. It predates this issue, but lowering 1,000 -> 400 moves it from "needs 1,000 nearby matches" to "needs 400", and the nearby segment auto-pages on scroll, so it takes no press at all to reach. Not fixed here, deliberately: the clamp is on the COMBINED row count, so no press could add a distant row without dropping a nearby one, and offering one would be exactly the no-op the rest of the file is careful to avoid. A real fix is a per-segment budget — a design change, not a constant. Pinned with a test instead, so it is asserted rather than rediscovered. Also corrected: - "roughly 15 deliberate presses past the first" contradicted auto-paging, which reaches the ceiling with none. - The content-visibility A/B was reported as "doubling p95" against the 36ms baseline of its own noisier run, next to a 17.4ms figure from a different run. Both baselines are now named, and the claim is +64%. - "showed exactly that shape" overclaimed. react-virtual was never profiled end-to-end — the browser-native analogue was, so windowing here is a LIKELY regression, inferred, not a measured one. Said plainly. - "NOT a jank threshold" then justified 400 by a smoothness measurement. Split into the two questions it was eliding: why a ceiling at all (DOM hygiene) and why 400 (deepest depth actually profiled smooth). - NODE_BUDGET is ours, not an external standard; Lighthouse warns an order of magnitude lower. Said so rather than implying authority. - The ratchet test moved to its own `describe` — it constrains the constant, not `revealRows` — split one assertion per case, and now admits 22 nodes/row is an average over real cards. - Measurement prose trimmed to one home; the satellites point at it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Deploying sahajatlas-design with
|
| Latest commit: |
1d26c7f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e9aa9890.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://perf-virtualize-list.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| Latest commit: |
1d26c7f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://83560720.sahajatlas.pages.dev |
| Branch Preview URL: | https://perf-virtualize-list.sahajatlas.pages.dev |
This was referenced Aug 7, 2026
Unrelated to this PR's change — the branch touches no dependency files, so the audit result is a pure function of the base lockfile and the advisory database, and main fails identically. Fixing a pre-existing red gate in the PR that hit it, per .claude/skills/pr-prep. Neither package can be upgraded away here: image-size has no fix published, and both arrive as transitives. So they are baselined, which the file documents as the reviewable path — and each entry records the evidence rather than an assurance: - image-size (GHSA-w3rx-r6r6-pgpr, GHSA-5p2g-fcmc-qvqq) comes via @payloadcms/sdk > payload, a TYPES-ONLY dependency. Verified absent from the built bundle: no `image-size` or `ICNS` string anywhere in dist/. No parser of ours is ever handed an image. - nanoid (GHSA-28wg-ghj8-5hjv, GHSA-2v37-7h3g-55p8) is a build-time transitive via tailwind-variants > tailwindcss > postcss — the same class already booked under #101. Also verified absent: the single `nanoid` string in dist/ is zod's `.nanoid()` string validator, an unrelated method name, and nanoid's own `urlAlphabet` export appears nowhere. Both verifications are stated in the baseline entries so the next reader can re-run them rather than take this on trust. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
4 tasks done
Ardnived
added a commit
that referenced
this pull request
Aug 8, 2026
Four high advisories published 2026-08-07 against the existing lockfile (image-size x2, nanoid x2) turned the audit gate red on every open PR, none of which touch either package. Both are verified absent from the shipped bundle by build + grep — payload is types-only so image-size never ships, postcss is build-time, and the one 'nanoid' string in dist/ is zod's .nanoid() validator name. image-size has no published fix; nanoid's is held back by postcss's own pin and arrives free under #101. Baselined against #101 with per-entry reasoning. Unblocks #123, #125, #126, #127.
Conflict in scripts/audit-baseline.json: this branch baselined the four 2026-08-07 advisories to get its own CI green, and #128 then landed the same four as a dedicated change. Took main's version wholesale — same four ids, fuller per-entry reasoning, and one owner for the file rather than an audit decision buried in a perf diff. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The ticket asked to virtualize the search-results list, with "lower
MAX_REVEAL" as thesanctioned fallback if the virtualizer fought vaul's scroll container. The scroll
container was never the problem — the ticket's premise was. Profiled in the real drawer
at 6× CPU throttle, mounted row count has no measurable effect on scroll cost, while the
thing virtualization would add (re-rendering cards as they enter the viewport) is the
single most expensive thing this list does.
MAX_REVEAL1,000 → 400 rows.→ ~8,900), not on smoothness — and the code, the rule doc and a new ratchet test all now
say so, so the next person doesn't re-derive the wrong conclusion.
@tanstack/react-virtualwas installed, measured against andremoved;
package.jsonandpnpm-lock.yamlare unchanged and the eager payload isbyte-identical.
The measurements
Running widget, seeded local backend, Playwright MCP,
Emulation.setCPUThrottlingRate: 6.Identical scroll (40px/frame × 100), same session. "Jank" = frame over 32 ms.
Six times the DOM scrolled strictly better. Tagging each frame with whether the row count
changed on it: 1 of 71 janky frames coincided with row growth — the cost is the
useTransitionreveal rendering the next 25 cards, not the rows already mounted.Independent corroboration: an A/B of the browser-native equivalent (
content-visibility: auto, which skips rendering offscreen rows) doubled p95 (36→59 ms) and quintupled theworst frame (61→307 ms) on the same list. Making rows re-render on viewport entry is the
shape a virtualizer produces, from a different mechanism, and it loses.
Changes
src/lib/shape/reveal.ts—MAX_REVEAL:PAGE_SIZE * 40→PAGE_SIZE * 16. Docblockrewritten to carry the measurements and state plainly that this is a DOM bound, not a
jank threshold. A second comment's stale
1000literal now spells the constant.src/lib/shape/reveal.test.ts— ratchet test pinning the ceiling to the node budget itwas measured against. Every pre-existing ceiling test spells the bound as
MAX_REVEAL,so all of them pass just as happily at a million; this one doesn't.
src/hooks/use-reveal.ts— records that theuseTransitionis load-bearing, with thenumbers.
.claude/rules/i18n-and-state.md— corrects "clamped atMAX_REVEAL, since the rows areunvirtualized" to the real reason, and records why virtualizing was rejected.
Verification
pnpm size✓LoadMore.test.tsxpasses unmodified, as the ticket requires.Manual verification (browser, real vaul drawer)
Everything below is unchanged by this PR — verified because the ticket makes them the
acceptance bar, and because they are exactly what a virtualizer would have put at risk:
label reads "Show distant events"; an explicit press advanced 63 → 88 and the label
stayed "distant".
aria-busysemantics — the control never carrieddisabledin any observed state./gb/south-east/slough/395),navigated back, list still at 88 rows. No reset call added; reset stays by-construction.
<body>./api/events/167; sweeping 14 rows fired1 request, so perf(api): tune caching, retries, and prefetch pressure #97's 150 ms dwell gate and 2-in-flight cap are intact.
The
/code-reviewpass caught this and I confirmed it live. When the nearby segmentalone fills
MAX_REVEAL, the control disappears and the entire distant segment becomesunreachable for that search:
The 50 distant events cannot be reached by any interaction; the only acknowledgement is
the
sr-onlylive region still counting to 460.This predates #98 — but it needed 1,000 nearby matches before and needs 400 now, and
the nearby segment auto-pages on scroll, so it takes no press at all to hit. My first
docblock draft claimed the ceiling "never touches the auto-paged nearby segment", which
was simply false; that's corrected.
Deliberately not fixed here. The clamp is on the combined row count, so no press
could add a distant row without dropping a nearby one — offering one would be exactly the
no-op the rest of
reveal.tsis careful to avoid. A real fix is a per-segment budget,which is a design change rather than a constant, and wants its own ticket. It is now
pinned by a test so it is asserted rather than rediscovered.
Notes for reviewer
It sits just above the 331-row depth verified smooth, so it is a measured bound rather
than a guess. But lowering a ceiling makes it more reachable: at production feed size, if
a dense metro's nearby segment runs past 400, a reader who just keeps scrolling now
hits the ceiling where at 1,000 they almost certainly would not have, and those results
become reachable only via a filter or a new search. Invisible on the 351-event seed;
not invisible in production. Judged acceptable because 400 rows is ~53,000 px — about 66
viewport-heights — and a ranked list is not the right tool for someone that deep. If you
disagree, the fix is to raise it and re-run the profile; the ratchet test enforces the
second half.
EventListItemrenders its own
<li>, and every correct route needs a ref +data-indexon that element(absolute positioning needs per-item style; dynamic measurement needs
measureElement).Rows genuinely vary in height, so a fixed
estimateSizegives a wrong total height andbreaks the scrollbar, the
LoadMoreobserver's position and scroll-to-end — the"half-working virtualizer" the ticket said not to ship. That file belongs to the sibling
caching/prefetch ticket, so it is untouched here.
as the risk and calls
React.memo+useTransition"mitigations, not a fix". Themeasurements say they are addressing the actual cost. The real follow-up lever is the
per-card render (
EventFacts/EventChipsand their date formatting), not the row count.1000comments are deliberately left inEventListItem.tsx:44anduse-prefetch-event.ts:84— both owned by the sibling ticket, both still directionallytrue, and editing them would only manufacture a conflict.
.claude/reports/98-virtualize-list.md.One unrelated commit: a pre-existing red audit gate
1d26c7fbaselines four advisories (image-size×2,nanoid×2) published since theaudit gate landed. Not caused by this branch — it touches no dependency files, so the
audit result is a pure function of the base lockfile plus the advisory database, and main
fails identically. Fixed here per
.claude/skills/pr-prep's pre-existing-failure rule;without it the PR is unmergeable.
Neither is upgradable (image-size has no published fix; both are transitives), so
baselining is the file's documented path. Each entry records verification, not
assurance — both were confirmed absent from the built bundle:
image-sizearrives under@payloadcms/sdk > payload, a types-only dependency; noimage-sizeorICNSstring appears anywhere indist/.nanoidis a build-time transitive (tailwind-variants > tailwindcss > postcss); thesingle
nanoidstring indist/is zod's.nanoid()string validator, anunrelated method name, and nanoid's own
urlAlphabetexport appears nowhere.Happy to split this into its own PR if you'd rather keep the perf diff clean.
Review coverage actually completed
/simplify— the branch adds no new code paths (one constant, one test block,comments), so there was no structure to simplify; nothing changed.
/code-review— one full pass completed (dispatched subagent,origin/main..HEAD).It found no bugs in the diff but three overclaims and a missing test case; all are fixed
in
65e42cb, including the stranding edge above. Two findings were dismissed withreason: stale
1000comments inEventListItem.tsx:44anduse-prefetch-event.ts:84,both owned by the sibling caching/prefetch ticket, both still directionally true, and
editing them would only manufacture a conflict.
/security-review— skipped, correctly: both gates infinalize-prstep 3return no match. No
src/config/api/,Widget.tsx, lexical,EventPanel,types/event,package.json,.envorvite.config.ts; no newdangerouslySetInnerHTML/innerHTML/ DOMPurify sink.Closes #98
🤖 Generated with Claude Code