0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
router/benchmarks/ssr
Manuel Schiller bc57fa3f12
fix(router-core): review follow-ups for Link stack (#8410)
* chore(benchmarks): remove TSR_LINK_PERF opt-in flag

The router-core Link/path benchmarks and the react-link-performance
project are never part of the CodSpeed matrix or the client-nav/SSR
aggregate projects, so the env-var gate only added friction. Rely on
standard vitest name filtering (-t) to narrow runs instead.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(router-core): treat 0 and false as provided _splat values

Splat interpolation used a falsy check, so _splat: 0 was omitted like a
missing param while $id: 0 interpolated to '/0'. Only undefined, null,
and '' now omit a splat segment, matching how other path params are
stringified.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(router-core): use path-derived ids in original-param-names fixtures

The matcher only uses route ids as routesById keys and for the pathless
'_' check, so unrelated ids worked but never occur in a real router.
Align the fixtures with the sibling test file's convention where each
id mirrors its fullPath.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* perf(solid-router): shorten conditional Link class and style spreads

Spread `cond && { value }` instead of `cond ? { value } : undefined`,
matching the neighbouring `active && STATIC_ACTIVE_ATTRIBUTES` spread.
Falsy operands spread to nothing, so the emitted props are unchanged.

Measured with the bundle-size benchmark on solid-router.full:
gzip 39205 -> 39198 (-7), raw -12, brotli -33.

Covered by the existing `six-adults-open` changeset.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(router-core): drop the unused server axis from interpolatePath tests

The `interpolatePath (server: $server)` block never read its `server`
argument since interpolation stopped taking a server flag, so it ran every
case twice under a misleading label. The remaining diff is re-indentation;
review with `git show -w`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(router-core): interpolate paths through the production API in tests

`interpolateTestPath` only survived as a compatibility layer from the
segment-reuse refactor: it emulated the removed
`(path, params, decoder, usedParams, keys, metadata)` signature by parsing
the template, re-implementing the param-name loop and folding
`hasMissingPathParams` into a metadata flag.

Call the real functions instead. Tests now parse templates with
`parseSegments(false, { fullPath }, 0)` exactly like `buildLocation` does
for templates without a processed route, pass the segments to
`interpolatePath`, and read names and availability from `getParamNames`
and `hasMissingPathParams`. The prepared-route tests compare route-owned
segments against that standalone parse directly, and the interpolation
bench derives its reference values the same way.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
History 2026-09-13 13:55:08 +02:00
..
react test: stabilize CPU simulation with isolated SSR workers and explicit V8 settings (#8248) 2026-09-05 20:54:53 +02:00
scenarios fix: upgrade TanStack Store to latest (#7824) 2026-09-10 19:41:24 +02:00
solid test: stabilize CPU simulation with isolated SSR workers and explicit V8 settings (#8248) 2026-09-05 20:54:53 +02:00
vue test: stabilize CPU simulation with isolated SSR workers and explicit V8 settings (#8248) 2026-09-05 20:54:53 +02:00
bench-utils.test.ts test: stabilize codspeed CPU benchmarks (#7987) 2026-08-06 16:46:19 +02:00
bench-utils.ts test: stabilize codspeed CPU benchmarks (#7987) 2026-08-06 16:46:19 +02:00
package.json test: stabilize CPU simulation with isolated SSR workers and explicit V8 settings (#8248) 2026-09-05 20:54:53 +02:00
README.md fix(router-core): review follow-ups for Link stack (#8410) 2026-09-13 13:55:08 +02:00
tsconfig.json test: stabilize CPU simulation with isolated SSR workers and explicit V8 settings (#8248) 2026-09-05 20:54:53 +02:00
vitest.config.ts ssr benchmarks (#7606) 2026-06-12 22:04:10 +02:00
vitest.react.config.ts ssr benchmarks (#7606) 2026-06-12 22:04:10 +02:00
vitest.solid.config.ts ssr benchmarks (#7606) 2026-06-12 22:04:10 +02:00
vitest.unit.config.ts test: stabilize codspeed CPU benchmarks (#7987) 2026-08-06 16:46:19 +02:00
vitest.vue.config.ts ssr benchmarks (#7606) 2026-06-12 22:04:10 +02:00

SSR Benchmarks

Cross-framework SSR request-loop benchmarks for:

  • @tanstack/react-start
  • @tanstack/solid-start
  • @tanstack/vue-start

Each benchmark builds a Start app with file-based routes and runs Vitest benches against the built server handler.

Layout

  • react/ - React Start baseline benchmark + Vitest config
  • solid/ - Solid Start baseline benchmark + Vitest config
  • vue/ - Vue Start baseline benchmark + Vitest config
  • vitest.react.config.ts, vitest.solid.config.ts, vitest.vue.config.ts - per-framework aggregate configs that run the baseline first, then scenario projects
  • scenarios/<scenario>/<framework>/ - isolated scenario apps

Scenario app layout:

scenarios/<scenario>/<framework>/
  vite.config.ts
  speed.bench.ts
  tsconfig.json
  src/
    router.tsx
    routes/
    routeTree.gen.ts

Each scenario uses one app per framework instead of sharing routes in the baseline app. This keeps route-tree size, middleware, Start options, and generated route trees isolated so one scenario cannot shift another scenario's numbers. The existing baseline apps and bench names stay stable for CodSpeed continuity.

Scenario Responsibilities

Each scenario isolates one Start server-side responsibility so benchmark changes can be attributed to a specific feature area.

Scenario Start server-side responsibility
react/, solid/, vue/ baseline apps Document SSR for nested file routes, route matching, search parsing, and full-page HTML response generation.
assets Per-request asset pipeline work: CSS inlining, CDN asset URL transforms with uncached manifest resolution, and response Link header collection for early hints.
before-load Nested beforeLoad execution: sequential per-match context building, context merging across matches, and context consumption by loaders during document SSR.
control-flow Loader-thrown redirect, notFound, plain errors, unmatched routes, and route headers() emission, including HTTP status selection, redirect location headers, route error boundaries, and not-found HTML rendering.
global-middleware Global createStart middleware registration: request middleware wrapping document SSR, server-function, and server-route requests, plus global function middleware on server functions.
head Nested route head evaluation, title/meta/link serialization, and head-entry deduplication during SSR.
loaders Nested route loader execution, loader deps from search params, router context reads, and dehydrated loader payload generation.
rewrites Composed location rewrites from router basepath plus locale input/output rewrites; unprefixed URLs redirect to /app/* when the basepath output rewrite canonicalizes them.
serialization Dehydration and RPC serialization of rich non-plain-JSON types: seroval native types in loader payloads, custom serialization adapters, and shallow-error serialization.
selective-ssr Route-level ssr modes: rendered server HTML with ssr: true, dehydrated data without HTML with ssr: 'data-only', and client-only omission with ssr: false.
server-fn-transport Non-JSON server-function transport: multipart/FormData request decoding, raw Response returns, and RawStream streamed responses through the binary frame protocol.
server-fns createServerFn GET/POST request handling, thrown redirect/notFound results, sendContext serialization, SSR-time direct calls, middleware context, input validation, and URL discovery.
server-routes File route server.handlers dispatch for parameterized JSON API routes without document HTML rendering.
server-routes-middleware Server route request middleware chains, middleware-provided context merging, and handler access to accumulated context.
streaming Deferred loader data, Await/Suspense fallback output, larger streamed HTML body scanning, streamed HTML ordering, and later dehydration payload emission.

Run

Run all benchmarks through Nx so dependency builds are part of the graph:

pnpm nx run @benchmarks/ssr:test:perf --outputStyle=stream --skipRemoteCache

Run framework-specific benchmarks:

pnpm nx run @benchmarks/ssr:test:perf:react --outputStyle=stream --skipRemoteCache
pnpm nx run @benchmarks/ssr:test:perf:solid --outputStyle=stream --skipRemoteCache
pnpm nx run @benchmarks/ssr:test:perf:vue --outputStyle=stream --skipRemoteCache

Build framework-specific benchmark apps:

pnpm nx run @benchmarks/ssr:build:react --outputStyle=stream --skipRemoteCache
pnpm nx run @benchmarks/ssr:build:solid --outputStyle=stream --skipRemoteCache
pnpm nx run @benchmarks/ssr:build:vue --outputStyle=stream --skipRemoteCache

Typecheck benchmark sources:

pnpm nx run @benchmarks/ssr:test:types --outputStyle=stream --skipRemoteCache

Run one scenario app manually through Nx:

pnpm nx run @benchmarks/ssr-<scenario>-<framework>:build:ssr --outputStyle=stream --skipRemoteCache
pnpm nx run @benchmarks/ssr-<scenario>-<framework>:test:types:ssr --outputStyle=stream --skipRemoteCache

Use react, solid, or vue for <framework>. The baseline projects use @benchmarks/ssr-<framework> without a scenario segment.

Request Conventions

  • Document GET loops use accept: text/html, matching the baseline request shape.
  • Server-function loops must include sec-fetch-site: same-origin so the default CSRF middleware accepts the request.
  • Loops that expect non-200 responses pass a custom validateResponse to runRequestLoop.
  • Bench loops must build deterministic requests from the seeded random helper and consume response bodies through runRequestLoop or runSsrRequestLoop.

The opt-in Link suite adds focused standalone React Router SSR coverage for params/updaters, inheritance, search middlewares, optional/splat segments, encoding, masks, rewrites, and active props. Each timed batch creates four fresh routers and renders their Links to HTML; it does not measure Start HTTP/streaming overhead.

CI=1 NX_DAEMON=false pnpm nx run @benchmarks/react-link-performance:test:perf:ssr --outputStyle=stream --skipRemoteCache -- --run

These cases are excluded from this directory's aggregate projects and normal CodSpeed dependency graph; they only run through the dedicated target above.