~ knotless Search/
↑↓ move↵ open⇧↵ all results

grain.social/grain

photography-focused photo sharing platform

grain.social
1 collaborator
0
2

next: Home's first card loads at once, the page's work after load

Merged
Merged chadtmiller.com asked to merge into feature/hud from grain.social/grain:next/perf

What changes

Home's hero is its first photo. HUD's ui::hero passes over a list that scrolls sideways (strip, shelf), so Home's preloaded, high-priority hero is its first card's first photo, not the first story's 110 KB avatar. That part is HUD's server: it shows once hud-next runs HUD at 5addfcf.

Pictures load by place, the hero first. The pictures first on the screen by their place load at once: an Image and a Gallery's first picture, at the tree's top, in a list's first item, in the pane shown. Home's first card, its face and first photo, is drawn so, and its carousel's next photo stays lazy, as do the later cards. Beside a hero they load with fetchpriority="low", so a gallery's author's 170 KB face no longer shares the bandwidth of its first photo, and on Home the first card's face and first story wait for the photo. A Covers under a gallery waits, but for its hero.

Less work while the page loads. A screen under the top one that never showed, such as Home's feed streamed under a gallery opened by its URL, is drawn only once it shows: on a gallery page that was 12 cards rendered and laid out unseen. The viewport read-ahead waits for load and idle, makes two calls at a time, and skips inert screens. A screen uncovered again has its links watched afresh, so those in view while it was covered are read ahead after all. Intl formatters and the grapheme segmenter are made on first use.

24px targets. The ALT badge's name holds its word ("Show ALT text"), and it and the ⓘ are 24px targets with the same pill drawn inside. A Link drawn as a name or a muted line (a feed card's place) is padded to 24px where its line is shorter, the padding taken back from its margins, so it lays out and looks as before.

vendor/hud is HUD at 5addfcf (app/shell, which holds feature/hud's 84d7175). next/ aliases @hud/shared/* to vendor/hud/web/shared/src, since HUD's shared code is now the @hud/shared package, and $shared/* is gone. feature/hud (Grain on Android) is merged in.

Why

Lighthouse mobile on next.grain.social gave Home 0.48 to 0.82 and the gallery 0.80, accessibility 0.96 on both. Home's LCP element is the first feed photo, which was loading="lazy" while the first story's avatar held the preload and high priority. The gallery's TBT came mostly from rendering and laying out Home's feed under it. Once the first photo was eager, the gallery's author's face, eager too and as large as the photo, loaded beside it at the same priority: low priority beside a hero keeps it eager (it is on the screen) without competing.

How it was checked

Lighthouse mobile (simulated throttling), signed out, on this machine: a release HUD (HUD_WORKSPACE=off, HUD_APPS a copy of this branch's next/) fronting a production build of next/ (HUD_WEB), each reading the network. Three such stacks side by side: HUD at app/shell's 13b5352 with next/ vendoring it (before), at 5f222fe (this pull's previous head), and at 5addfcf (now). Five runs of each page, interleaved, medians:

PageHUDPerfLCPTBTAccessibility
Homebefore (13b5352)0.766.02 s26 ms0.96
Home5f222fe0.795.21 s30 ms0.96
Homenow (5addfcf)0.824.59 s32 ms1.0
Gallerybefore (13b5352)0.824.34 s141 ms0.96
Gallery5f222fe0.844.15 s12 ms1.0
Gallerynow (5addfcf)0.873.84 s11 ms1.0

The gallery is /profile/aaronstevenwhite.io/gallery/3n2gk44hcsdvf. Its LCP element is its first photo in every run, and Home's is its first card's first photo (a new post took the first card after the first round, for all three alike). On the gallery, before, its author's face started with the photo at high priority. Now it starts with it at low. The LCP regression measured earlier against the live HUD (4.35 to 4.72 s) didn't show here at 5f222fe, and the low priority takes the gallery 0.3 s under it.

  • HUD: npm run check, npm run unit (40 pass), npm run ssr, just lint, and just cov at 100% of lines and functions. ssr.mjs checks that the hero is eager, high priority and preloaded as drawn, that a picture first on the screen by its place is eager at low priority beside a hero (with no priority in a tree without one), that Home's first story's face and first card's are those, and that the rest are lazy. In Chromium, a feed card's place is 24px tall where it was 20.3px, every other box in the card where it was. Going back to Home after opening a card whose neighbours had just scrolled into view now reads those neighbours ahead (three calls), where 5f222fe read none.
  • grain: node next/check-apps.mjs and npm run check in next/.
  • Deploy safety: hud check at 5addfcf's server code loads next.grain.social's live apps and this branch's next/, with HUD_WORKSPACE off and on, with no problem.

Shortcomings

  • Home's hero moves only once hud-next runs HUD at 5addfcf: until then the live page preloads the story avatar, and the first photo, eager, competes with it.
  • The numbers are local, with time to first byte 0.5 to 0.9 s through a local HUD reading the network. Absolute LCPs are higher than next.grain.social's behind Cloudflare. The comparison holds, since the three stacks ran side by side over the same feed.
  • Home's TBT spike (2.5 s in one live run) never reproduced. The fixes cut the work the page does as it loads but weren't shown to fix it.
  • The vendor bump brings app/shell's small changes to HUDKit and hudkit (the SDK's packaging, the registries' names) into ios/ and android/. hudkit now names its version from the hudVersion Gradle property, which android/gradle.properties gives (0.2.0, HUD's at vendor/hud/COMMIT): without it the android check failed to configure. The iOS app wasn't built here, and Android only by CI's android check.

Review

Start at vendor/hud/web/renderer/src/Picture.svelte and hero.ts, then shell/src/Stack.svelte (shownOnce), prefetch.ts and renderer/src/tree/Link.svelte.

Approved

This pull bumps vendor/hud to 1d5b910 and moves the @hud/shared alias in next/. Three things come with the bump:

  • Pictures that are first on the screen by their place now load eagerly.
  • Stack no longer draws an under-screen that never showed.
  • The viewport read-ahead is deferred and throttled.

I read the next/ changes and the changed renderer and shell files in vendor/hud. I did not read the iOS/HUDKit changes or the small shared re-export stubs: they aren't web paths and next/ doesn't build them. The vendor tree isn't hand-edited, so I judged those files as the copy of HUD's change.

I found nothing that must change.

  • The First/setFirst context chain holds up. Tree is the root, List makes only item 0 first, Panes only the shown pane, and outside a tree firstOf defaults to false.
  • shownOnce is filled in an $effect, which doesn't run during server rendering, so the server draws only the top level. Hydration therefore matches, and a level stays drawn once it has shown.
  • The @hud/shared/* alias is consistent across tsconfig, vite and the sitemap import.

One minor point. In prefetch.ts a link that intersects while its screen is inert is skipped, and the observer is not re-armed when that screen becomes the top one. Links already in view on a returning screen therefore get no viewport read-ahead until they leave and re-enter the viewport. Hover and press still read ahead, so it only costs a little speed and not correctness.

The home preload only moves once hud-next runs the new HUD, as the body says.

Approved

Since my approval at bdef2db, the pull only re-vendors HUD to 5f222fe. The change removes the explicit eager prop from CoverCard, CoverTile and Covers. Picture already decides this from the firstOf() context, and First.svelte and PaneBody.svelte set that context. The first cover therefore still loads eagerly where it is first on the screen, and the props were redundant. I found nothing that breaks the earlier approval. I did not re-check the minor prefetch.ts point from last round. It only costs a little speed and not correctness.

chadtmiller.com added 1 commit

On the prefetch.ts point: fixed in HUD 5addfcf (vendored here). The read-ahead's MutationObserver now watches inert too; when a screen's inert is let go, its links not read ahead yet are unobserved and observed again, so the IntersectionObserver reports those already in view. A link counts as read only once its call is queued, so one whose timer found its screen covered is watched again too. In Chromium (mobile, no hover), scrolling Home and opening a card within 400 ms, then going back, now reads the newly shown neighbours ahead (three calls), where 5f222fe read none.

Approved

Since my approval at 7c3c523, the pull re-vendors HUD to 5addfcf. That adds the hero-by-place logic and the 24px targets for ALT, ⓘ and Link names. It also reworks the prefetch (read-ahead) code. I read the changed Picture, hero.ts, Link, AltBadge, InfoBadge, Stack and prefetch.ts files from the pull diff. I did not read the iOS and Android HUDKit changes, the package.json files or the other one-line import swaps. They aren't web paths, and the body says they weren't built.

I found nothing that must change.

  • Priority logic: Picture sets fetchpriority to high only for the hero. It sets low for a picture loaded at once beside a hero, and leaves it unset in a tree with no hero.
  • Earlier prefetch.ts point: my earlier concern is now handled. The observer watches the inert attribute and re-observes links once their screen is uncovered, and done stops links that were already read from being read again.
  • 24px badges: the badges are bare 24px boxes with the pill drawn inside, and their names now hold "ALT".

One minor point. stop() clears the shared #waiting queue, so it also drops calls queued by another screen's readAhead on the same Ahead. The cost is a little read-ahead speed, not correctness.

Approved

Since my approval at f0b6cb0, the only change is hudVersion=0.2.0 in android/gradle.properties. hudkit reads that property to name its version, and the body says the Android check failed to configure without it. The value only labels the module, so it doesn't touch the web changes I approved. I found nothing that must change.

On stop() clearing the shared #waiting: one readAhead runs per Ahead. Shell.svelte attaches it once, to <main> ({@attach reading.readAhead(linked)}), and nothing else calls it. The attachment re-runs only when linked changes, and then the new one starts afresh, so stop() drops only its own queue, which is stale by then. If a second caller ever shares an Ahead, each should keep its own queue. Left as it is.

Approved

Since my approval at d3822a1, the only change is a merge of feature/hud into the branch. The merge brought in the already-merged "HUD's own hud check, the app's lexicons and its HUD version" pull. I read the three conflict files named in the merge message: vendor/hud/COMMIT, next/vite.config.ts and android/gradle.properties.

  • vendor/hud/COMMIT still says 5addfcf, so the HUD vendor bump I approved stands.
  • next/vite.config.ts keeps the @hud/shared/* alias to vendor/hud/web/shared/src, and its comment now names it.
  • android/gradle.properties no longer differs from the base, because the base already carries hudVersion. The pull's duplicate of that change dropped out cleanly.

I did not read the rest of the large merge diff. It is the base's own changes, not the pull's. I found nothing that breaks my earlier approval.

Merged as 15d2b22
Part of a stack of 2
  1. next: Home's first card loads at once, the page's work after load Landed as 15d2b22
  2. main