Skip to content

perf(list): bound the results list by DOM budget, not virtualization - #125

Merged
Ardnived merged 5 commits into
mainfrom
perf/virtualize-list
Aug 8, 2026
Merged

Ardnived merged 5 commits into
mainfrom
perf/virtualize-list

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The ticket asked to virtualize the search-results list, with "lower MAX_REVEAL" as the
sanctioned 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.

  • Virtualizing this list was measured to be a likely regression, so the fallback ships:
    MAX_REVEAL 1,000 → 400 rows.
  • The bound is justified on DOM hygiene inside a host page we don't own (~22,000 nodes
    → ~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.
  • No dependency shipped. @tanstack/react-virtual was installed, measured against and
    removed; package.json and pnpm-lock.yaml are unchanged and the eager payload is
    byte-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.

List state rows DOM nodes median p95 max frames > 32 ms
Fully revealed, settled 331 7,331 8.3 ms 17.4 ms 28.2 ms 0 / 100
Actively auto-paging 50 1,079 38.4 ms 175 ms 1,447 ms 71 / 100

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
useTransition reveal 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 the
worst 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. Docblock
    rewritten to carry the measurements and state plainly that this is a DOM bound, not a
    jank threshold. A second comment's stale 1000 literal now spells the constant.
  • src/lib/shape/reveal.test.ts — ratchet test pinning the ceiling to the node budget it
    was 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 the useTransition is load-bearing, with the
    numbers.
  • .claude/rules/i18n-and-state.md — corrects "clamped at MAX_REVEAL, since the rows are
    unvirtualized" to the real reason, and records why virtualizing was rejected.

Verification

  • Lint ✓ · Typecheck ✓ · Tests ✓ 69 files / 747 passing · Build ✓ · pnpm size ✓
  • Bundle: 379.7 KiB standalone / 381.2 KiB embed — identical to base (budget 395).
  • LoadMore.test.tsx passes 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:

  1. Auto-paging within the nearby segment — 25 → 63 rows by scrolling alone, no presses.
  2. Distant boundary holds — 63 → 63 across six further scroll-to-bottom cycles; the
    label reads "Show distant events"; an explicit press advanced 63 → 88 and the label
    stayed "distant".
  3. aria-busy semantics — the control never carried disabled in any observed state.
  4. Position restore — opened an event from row 40 (/gb/south-east/slough/395),
    navigated back, list still at 88 rows. No reset call added; reset stays by-construction.
  5. Keyboard focus — Tab walked rows 6 → 17 contiguously, focus never reached <body>.
  6. Hover prefetch — dwelling fired exactly one /api/events/167; sweeping 14 rows fired
    1 request, so perf(api): tune caching, retries, and prefetch pressure #97's 150 ms dwell gate and 2-in-flight cap are intact.

⚠️ A pre-existing bug this change makes more reachable

The /code-review pass caught this and I confirmed it live. When the nearby segment
alone fills MAX_REVEAL, the control disappears and the entire distant segment becomes
unreachable for that search:

reveal([...near(410), ...far(50)], { shown: 400 })
→ { rows: 400, more: null, next: null, total: 460 }

The 50 distant events cannot be reached by any interaction; the only acknowledgement is
the sr-only live 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.ts is 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

  • The one judgement call is the number 400, and it has a real cost — please push on it.
    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.
  • Why no virtualizer is attemptable today, if you want to revisit it: EventListItem
    renders its own <li>, and every correct route needs a ref + data-index on that element
    (absolute positioning needs per-item style; dynamic measurement needs measureElement).
    Rows genuinely vary in height, so a fixed estimateSize gives a wrong total height and
    breaks the scrollbar, the LoadMore observer'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.
  • The readiness finding is partially corrected, not just closed. §1.3 frames row count
    as the risk and calls React.memo + useTransition "mitigations, not a fix". The
    measurements say they are addressing the actual cost. The real follow-up lever is the
    per-card render (EventFacts / EventChips and their date formatting), not the row count.
  • Two stale 1000 comments are deliberately left in EventListItem.tsx:44 and
    use-prefetch-event.ts:84 — both owned by the sibling ticket, both still directionally
    true, and editing them would only manufacture a conflict.
  • Full report (measurements, rejected options, AC table): .claude/reports/98-virtualize-list.md.

One unrelated commit: a pre-existing red audit gate

1d26c7f baselines four advisories (image-size ×2, nanoid ×2) published since the
audit 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-size arrives under @payloadcms/sdk > payload, a types-only dependency; no
    image-size or ICNS string appears anywhere in dist/.
  • nanoid is a build-time transitive (tailwind-variants > tailwindcss > postcss); the
    single nanoid string in dist/ is zod's .nanoid() string validator, an
    unrelated method name, and nanoid's own urlAlphabet export 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 with
    reason
    : stale 1000 comments in EventListItem.tsx:44 and use-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 in finalize-pr step 3
    return no match. No src/config/api/, Widget.tsx, lexical, EventPanel,
    types/event, package.json, .env or vite.config.ts; no new
    dangerouslySetInnerHTML / innerHTML / DOMPurify sink.

Closes #98

🤖 Generated with Claude Code

Ardnived and others added 3 commits August 7, 2026 10:46
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]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

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

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1d26c7f
Status: ✅  Deploy successful!
Preview URL: https://83560720.sahajatlas.pages.dev
Branch Preview URL: https://perf-virtualize-list.sahajatlas.pages.dev

View logs

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]>
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]>
@Ardnived
Ardnived merged commit c84c562 into main Aug 8, 2026
3 checks passed
@Ardnived
Ardnived deleted the perf/virtualize-list branch August 8, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(list): virtualize the results list

1 participant