Skip to content

perf(claims): return early for plain hrefs that cannot match the location - #748

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

brenelz wants to merge 2 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

Server link claims still cost a measurable share of SSR 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 claim handler off entirely raises SSR throughput by about 21% on a Linux runner. 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 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

  • plainHrefMisses(href, loc) in src/claims.ts returns true for a plain root-relative href (characters URL keeps verbatim, no dot segments, no // start, no trailing slash) that is longer than the comparable location or is not a prefix of it. The handler then returns "" before building the attrs object. A plain 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 computed once and recomputed only when router.location.pathname changes.
  • utils.ts exports serverPlainPath and serverPlainHref (isServer ? fn : undefined), and claims.ts calls those instead of importing isPlainPath and plainHref directly. In client builds both bindings fold to undefined, so neither 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.

Verification

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

  • A new 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.

  • SSR throughput on Linux: ubuntu-latest (AMD EPYC 7763), with the tracker's app-solid built against router tarballs packed from main (7347290), 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
    this branch 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, this branch 38.9M–39.0M (about −7%), claim handler off 35.8M–36.9M. Of what remains, the isPlainPath regex is about 0.8M per request, which keeps the check sound.

  • Client JS on the same app: 142,367 to 142,080 B minified (−287 B), 48,955 to 48,819 B brotli (−136 B). Dropping plainHref saves 313 B minified, and the early exit adds 26 B.

Open

  • 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: 62459a7

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
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