Skip to content

perf: headroom under the public lanyard's loading budget (#177) - #179

Merged
renderghost merged 3 commits into
mainfrom
claude/zealous-faraday-h1asbk
Nov 21, 2026
Merged

renderghost merged 3 commits into
mainfrom
claude/zealous-faraday-h1asbk

Conversation

@renderghost

Copy link
Copy Markdown
Owner

Summary

The public lanyard's LCP sat on its 2.5 s budget, so e2e/perf.spec.ts failed intermittently. Three changes, one commit each, give it about 230 ms of headroom.

Change Median LCP (perf test's throttling, this machine)
Baseline ~2,300 ms
1. The entry loads as one file, not eight ~2,260 ms
2. A lanyard's own code loads as two chunks, not a dozen ~2,140 ms
3. The page's code starts downloading before React renders ~2,060 ms

An interleaved A/B against the original build on the same machine gave 2,280–2,300 ms before and 2,060–2,110 ms after, with a tighter spread. This machine runs about 170 ms faster than the one in the issue, so expect about 2,250–2,300 ms there.

1. Entry merge (vite.config.ts)

Rolldown split the code the entry shares with lazy routes into seven extra chunks, so every page started with eight JS files on HTTP/1.1's six connections. A $initial group puts that code back in the entry, which also saves 3.3 KB gzipped.

2. Lanyard chunk groups (plugins/lanyardChunks.ts)

A chunk group's name function reads the module graph and sorts what the public lanyard loads lazily into two chunks:

The build fails if a listed lanyard route stops being split, so the list can't drift. The lanyard's lazy burst drops from 11 files to 5. Two of those five are tiny lucide icons, which reach it through the entry's barrel.

3. Early route preload (src/app/preloadRouteCode.ts)

Called from main.tsx before the first render, it matches the location and starts the route's code downloading. It loads code only: beforeLoad and loaders still run once, and the router waits on the same download, so a failure still shows the route's error. Tests cover both.

Bundle sizes (gzipped, cold load)

Route Before After
/$handle (budget 200 KB) 199.8 KB, 11 lazy files 194.6 KB, 5
/d/$did 199.5 KB 194.4 KB
Home 181.0 KB 178.8 KB
Sign-in 188.5 KB 187.2 KB
Share 201.1 KB 216.4 KB

Trade-off: a cold load of Share now includes the lanyard's surface (+15 KB). Share is normally opened from your own lanyard, which has already loaded that code, so in practice it rarely costs anything.

What I tried and rejected

  • Preloading the route's chunks from index.html: made LCP worse (median ~2,380 ms). DevTools throttling shares bandwidth regardless of fetch priority, so the chunks slowed the entry. It also exposed the three-hop data chain (profile → DID document → PDS) as the next critical path.
  • Running the preload before React DOM evaluates: no measurable gain.

Testing

  • npm run lint, npm run typecheck, npm run lex:check, npm run i18n:check
  • npm test -- --run: 1,359 passed, including 13 new tests
  • npm run build:e2e, npm run size, npm run check:prod
  • npm run e2e: 95 passed, including perf; the perf spec alone passed 5 of 5 runs
  • Throttled waterfalls and traces checked in Chromium

Notes

Closes #177


Generated by Claude Code

renderghost and others added 3 commits November 21, 2026 16:00
Rolldown split the code the entry shares with lazy routes into seven
small chunks of its own, so every page started with eight JavaScript
files. Over HTTP/1.1, with six connections per host, they queued behind
each other and the font. A group for the entry's code ($initial) puts it
back in the entry: one file, and 3.3 KB less to download gzipped.

The public lanyard's median LCP under the perf test's throttling moves
from about 2,300 ms to 2,260 ms (nine cold loads each).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PSPB1dNXrwbP6tbCDtjLb9
Once the entry has run, a public lanyard loads its route's code: eleven
small files, one for each set of pages sharing a module. Over HTTP/1.1
the last five waited for a free connection, a second round trip before
the badge could render.

A chunk group's name function now reads the module graph and sorts what
the public lanyard loads lazily into two chunks:
- lanyard-page: what only a person's lanyard pages load (the public
  lanyard, the owner's own, the customiser and Share);
- lanyard-shared: what a lanyard shares with other pages, such as the
  badge's drawing on the homepage and sign-in, which the badge group
  (#173) held, and small helpers.
The build fails if a lanyard route stops being split, so the list can't
drift.

The lanyard now loads five lazy files (two of them tiny lucide icons,
which reach it through the entry's barrel), and 194.6 KB of initial JS
against 199.8 KB. The homepage, sign-in, feedback and the customiser load
fewer files and less JS; a cold load of Share loads the lanyard's surface
too (+15 KB gzipped), which a visit from the owner's lanyard has already
loaded.

The public lanyard's median LCP under the perf test's throttling moves
from about 2,260 ms to 2,140 ms (nine cold loads each).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PSPB1dNXrwbP6tbCDtjLb9
The router asks for the current route's lazy code only once React has
rendered and the router has started. preloadRouteCode, called from
main.tsx before the first render, matches the location and starts that
download as soon as the entry has run. It loads code only: each route's
beforeLoad and loader still run once, when the router loads it, and the
router waits on the same download, so a failure shows as the route's
error, as before.

The public lanyard's chunks are requested about 85 ms earlier, and its
median LCP under the perf test's throttling moves from about 2,140 ms to
2,060 ms (eighteen cold loads). Against the original build, interleaved
on one machine: 2,280–2,300 ms before, 2,060–2,110 ms after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PSPB1dNXrwbP6tbCDtjLb9
@vercel

vercel Bot commented Nov 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lanyards Ready Ready Preview Nov 21, 2026 4:18pm UTC

Base automatically changed from claude/lanyards-rebuild-attendee-ux-vcl1sb to main November 21, 2026 16:37
@renderghost
renderghost merged commit 8849f2f into main Nov 21, 2026
3 checks passed
@renderghost
renderghost deleted the claude/zealous-faraday-h1asbk branch November 21, 2026 16:38
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.

Public lanyard's LCP sits on its 2.5 s budget; the perf test fails intermittently

1 participant