Skip to content

perf(claims): skip link claims whose href cannot match the location - #748

Open
brenelz wants to merge 3 commits into
solidjs:mainfrom
brenelz:perf/ssr-link-claim-early-exit-main
Open

brenelz wants to merge 3 commits into
solidjs:mainfrom
brenelz:perf/ssr-link-claim-early-exit-main

Conversation

@brenelz

@brenelz brenelz commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Link claims still cost a measurable share of page time on pages with many links, even after #701. On the framework-tracker /server-side-rendered page (1000 row links to /server-side-rendered/<id>), turning the server claim handler off entirely raises SSR throughput by about 21% on a Linux runner. On the client-rendered /client-side-rendered page, the client claims spend about 4.5 ms of the 22 ms of page-load JavaScript concluding that each of the 1000 links is inactive. Separately, client builds ship plainHref and its regex even though only server claims call it.

Root cause

setupServerLinkClaims sends every anchor through managedLinkUrl (attribute normalization, plainHref, isUnderBase) and then through the location matcher. On the client, setupLinkClaims does the same for every claimed anchor through refresh: new URL(href, document.baseURI), isUnderBase, then comparablePath in the matcher. On a list page almost none of those links can be active. A link is only active when its path equals the location or is a parent of it, so any href longer than the location, or one that is not a prefix of it, can never match.

The client size issue comes from how the bundler splits chunks. It fixes a shared chunk's cross-chunk exports before the minifier removes the isServer branches, so a server-only call in claims.ts keeps the utils.ts function it imports alive in the client's routing chunk.

What changed

  • locationMisses(router) in src/claims.ts returns a check that is true for a root-relative href made of letter, digit, _ and - segments (/^(?:\/[\w-]+)+$/: no dot or empty segments, no trailing slash, nothing URL would rewrite) that is longer than the comparable location or is not a prefix of it. Such an href's comparable path is just its lowercase form, so this is exactly the matcher's rule: loc === path needs equal length, and loc.startsWith(path + "/") needs a longer location. The comparable location is recomputed only when router.location.pathname changes.
  • Server claims return "" for a miss before building the attrs object.
  • Client claims skip apply(linkState(a)) for a miss when there is no links plugin, the record does not own an aria-current, and the anchor has no data-active. In that case apply would change nothing. The check sits in refresh, so it covers the first claim, re-claims after an href write, and the location-change sweep. The anchor still joins the registry, so a later navigation that makes it active updates it. The check runs inside the existing untrack, so it adds no subscription to the creating computation.
  • utils.ts exports serverPlainHref (isServer ? plainHref : undefined), and claims.ts calls that instead of importing plainHref directly. In client builds the binding folds to undefined, so neither the function nor its regex ships. plainHref stays exported for the server fuzz test, which does not affect app bundles.

Rendered HTML is unchanged. On the tracker page it is identical to main once per-request UUIDs and asset hashes are stripped. Link attributes after load are identical on both tracker pages.

Verification

  • pnpm test: 770 client tests, 112 server tests and test:types pass.

  • A fuzz test in test/server/plain-href-fast-path.spec.ts checks 100,000 random href/location pairs (mixed case, ./.., %41, trailing slashes, queries, hashes). No href that linkMatcher marks active or current is ever reported as a miss. Fixed cases cover both outcomes.

  • test/claims-plain-miss.spec.tsx counts URL constructions on the client. On this branch, 20 unrelated links parse fewer than 5 URLs at claim and fewer than 10 across a navigation; the same test on the server-only commits parses 45. It also checks that the location and its parents are still marked, base paths, the fallback for a query, hash, %, .., //, trailing slash, relative and backslash href, that a links plugin turns the skip off, that a later navigation marks a skipped link, and that stale data-active or router-owned aria-current on a miss is still cleared while an authored one is kept. jsdom here cannot hydrate or resolve SVG href.baseVal, so those paths are not covered.

  • SSR throughput on Linux: ubuntu-latest (AMD EPYC 7763), with the tracker's app-solid built against router tarballs packed from main (7347290), the first commit of this branch, and main with the claim handler returning "" at once. The server runs in node:24.22.1-bookworm-slim pinned to CPUs 0-2, and autocannon in a second container on CPU 3. Each run is 10 connections, a 10 s warmup and a 20 s measurement, over six interleaved rounds:

    Router req/s (median, range) Server CPU ms/req
    main 215 (211–221) 6.10
    first commit 248 (240–252), +15% 5.38
    claim handler off 260 (258–265), +21% 5.29

    The early exit recovers about 73% of the throughput the claim handler costs on this page.

  • Instructions retired per request, measured in-process with handleRequest on macOS arm64 (/usr/bin/time -l, three interleaved rounds, after a 200-request warmup with the warmup cost subtracted): main 41.8M–42.2M, first two commits 38.9M–39.0M (about −7%), claim handler off 35.8M–36.9M.

  • Client page load on /client-side-rendered (minified build, headless Chrome 158 on an M2, CDP Profiler during goto, 16 loads per side, interleaved): page-load JS goes from a median of 22.3 ms (21.7–23.1) on the second commit to 17.9 ms (16.8–18.3) with the third. FCP median goes from 48 to 44 ms over 30 loads each, one 4 ms frame step.

  • Client JS on the tracker app (17 chunks, @solidjs/web 2.0.4): main 142,416 B minified / 48,990 B brotli, this branch 142,401 / 48,921 (−15 / −69). Dropping plainHref saves 313 B minified; the server and client early exits together add 298 B.

Open

  • The server numbers above were measured on the first two commits, whose server check also accepted ., ~ and other characters URL keeps verbatim. The third commit narrows it to letter, digit, _ and - segments, which keeps the shared check out of the client's routing chunk. Hrefs such as /docs/v1.2 or /file.pdf now take the full path on the server. The tracker's links still match, and I have not re-measured the server after this change.
  • Measured on a 4-CPU ubuntu-latest runner and an M2. The tracker's own CI uses a 16-CPU Depot runner, which I could not use from a fork.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f4607e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brenelz
brenelz marked this pull request as ready for review November 24, 2026 02:44
@brenelz brenelz changed the title perf(claims): return early for plain hrefs that cannot match the location perf(claims): skip link claims whose href cannot match the location Dec 1, 2026
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.

1 participant