Skip to content

perf(router-core): evaluate head/scripts across matches in parallel - #8145

Closed
Sheraff wants to merge 2 commits into
mainfrom
perf/task4-parallel-head-scripts
Closed

perf(router-core): evaluate head/scripts across matches in parallel#8145
Sheraff wants to merge 2 commits into
mainfrom
perf/task4-parallel-head-scripts

Conversation

@Sheraff

@Sheraff Sheraff commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • projectLane (load-server.ts + load-client.ts) awaited each match's head/scripts(/headers) sequentially — total latency was the sum of all resolutions instead of the max.
  • Now invokes all callbacks in the rendered prefix synchronously (route order), then awaits/applies results one match at a time in route order with the original per-match error/abort/break logic.

Behavioral equivalence (strict)

Each preserved ordering has a dedicated test in tests/head-scripts-parallel.test.ts (10 tests):

  • results applied in route order even when later matches resolve first
  • early-break semantics (ssr:false / error / _notFound) unchanged
  • deterministic route-order error surfacing; sync-throw handling; silent abort break
  • zero unhandled rejections (catch handlers attached to every promise, incl. discarded ones)

Caught during verification: a first implementation wrapped results in an extra .then layer; that single extra microtask tick flipped a real scheduling race so runBackground's publish landed after router.load() resolved — caught by the existing public-hydration-contract.test.ts. Fixed by awaiting the raw attempt promise (identical await-chain depth to original).

Performance

N=6 heads × 60ms: sequential 362ms → projectLane 62ms (~max, not sum).

Verification

test:unit ✅ (107 files / 1616 tests) · eslint ✅ · types ✅

Residual risks (documented in RESULT-perf-task4.md)

  1. head fns for the whole prefix are invoked up-front: a fn reading another match's already-applied head result would see it unapplied (loaders are guaranteed complete first; contract tests pass).
  2. Under abort, later prefix callbacks may be invoked before the abort is observed.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d6604a90-c248-428d-9f31-65191e577b15

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 6f0657277db8
  • Measured at: 2026-08-22T06:03:40.210Z
  • Baseline source: history:d83a8964c250
  • Dashboard: bundle-size history

The following scenarios have bundle-size changes compared with the baseline:

Scenario Current (gzip) Initial (gzip) Raw Brotli Trend
react-router.minimal 83.9 KiB
+52 B
83.8 KiB
+56 B
263.0 KiB
+177 B
73.0 KiB
-3 B
▃▂▂▁▁▃▃▃▂▄▄█
react-router.full 87.4 KiB
+58 B
87.3 KiB
+57 B
274.7 KiB
+177 B
76.1 KiB
+93 B
▂▂▂▁▁▃▃▃▂▄▄█
solid-router.minimal 33.3 KiB
+61 B
33.1 KiB
+61 B
96.8 KiB
+177 B
30.0 KiB
+22 B
▁▁▁▄▄▅▅▅▅▅▅█
solid-router.full 38.1 KiB
+61 B
38.0 KiB
+60 B
111.5 KiB
+177 B
34.4 KiB
+108 B
▁▁▁▅▅▆▆▆▅▅▅█
vue-router.minimal 49.6 KiB
+62 B
49.5 KiB
+63 B
138.8 KiB
+177 B
44.8 KiB
+119 B
▁▁▁▁▁▄▄▄▂▃▃█
vue-router.full 55.2 KiB
+62 B
55.1 KiB
+62 B
157.0 KiB
+177 B
49.7 KiB
+42 B
▁▁▁▁▁▄▄▄▂▃▃█
react-start.minimal 96.8 KiB
+56 B
96.7 KiB
+56 B
305.2 KiB
+177 B
83.9 KiB
+87 B
▂▁▁▄▄▅▅▅▅▆▆█
react-start.deferred-hydration 97.5 KiB
+61 B
96.7 KiB
+57 B
306.6 KiB
+177 B
84.6 KiB
+76 B
▂▁▁▄▄▅▅▅▅▆▆█
react-start.full 100.0 KiB
+53 B
99.8 KiB
+53 B
315.0 KiB
+177 B
86.6 KiB
+79 B
▁▁▁▄▄▅▅▅▄▆▆█
react-start.rsbuild.minimal 100.1 KiB
+64 B
99.9 KiB
+64 B
315.5 KiB
+177 B
86.3 KiB
-89 B
▂▁▁▄▄▆▆▆▄▅▅█
react-start.rsbuild.minimal-iife 100.5 KiB
+62 B
100.4 KiB
+62 B
316.4 KiB
+177 B
86.7 KiB
+63 B
▂▁▁▃▃▆▆▆▄▅▅█
react-start.rsbuild.full 103.4 KiB
+59 B
103.3 KiB
+59 B
325.6 KiB
+177 B
89.1 KiB
+93 B
▂▁▁▃▃▆▆▆▅▅▅█
solid-start.minimal 46.1 KiB
+55 B
46.0 KiB
+55 B
137.9 KiB
+177 B
41.0 KiB
+78 B
▁▁▁▅▅▆▆▆▆▆▆█
solid-start.deferred-hydration 49.2 KiB
+58 B
46.0 KiB
+61 B
145.4 KiB
+177 B
43.8 KiB
+112 B
▁▁▁▅▅▆▆▆▅▆▆█
solid-start.full 51.2 KiB
+58 B
51.1 KiB
+58 B
153.3 KiB
+177 B
45.3 KiB
+25 B
▁▁▁▅▅▆▆▆▅▆▆█
vue-start.minimal 65.7 KiB
+53 B
65.6 KiB
+54 B
189.7 KiB
+177 B
58.5 KiB
+11 B
▁▁▁▅▅▆▆▆▅▆▆█
vue-start.full 69.6 KiB
+53 B
69.4 KiB
+52 B
202.0 KiB
+177 B
61.7 KiB
-26 B
▁▁▁▅▅▆▆▆▅▆▆█

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

4 package(s) bumped directly, 19 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/react-router 1.170.31 → 1.170.32 Changeset
@tanstack/router-core 1.171.26 → 1.171.27 Changeset
@tanstack/solid-router 1.170.29 → 1.170.30 Changeset
@tanstack/vue-router 1.170.28 → 1.170.29 Changeset
@tanstack/react-start 1.168.48 → 1.168.49 Dependent
@tanstack/react-start-client 1.168.29 → 1.168.30 Dependent
@tanstack/react-start-rsc 0.1.47 → 0.1.48 Dependent
@tanstack/react-start-server 1.167.36 → 1.167.37 Dependent
@tanstack/router-cli 1.167.32 → 1.167.33 Dependent
@tanstack/router-generator 1.167.32 → 1.167.33 Dependent
@tanstack/router-plugin 1.168.34 → 1.168.35 Dependent
@tanstack/router-vite-plugin 1.167.34 → 1.167.35 Dependent
@tanstack/solid-start 1.168.46 → 1.168.47 Dependent
@tanstack/solid-start-client 1.168.28 → 1.168.29 Dependent
@tanstack/solid-start-server 1.167.35 → 1.167.36 Dependent
@tanstack/start-client-core 1.170.26 → 1.170.27 Dependent
@tanstack/start-plugin-core 1.171.38 → 1.171.39 Dependent
@tanstack/start-server-core 1.169.30 → 1.169.31 Dependent
@tanstack/start-static-server-functions 1.167.31 → 1.167.32 Dependent
@tanstack/start-storage-context 1.167.28 → 1.167.29 Dependent
@tanstack/vue-start 1.168.45 → 1.168.46 Dependent
@tanstack/vue-start-client 1.167.31 → 1.167.32 Dependent
@tanstack/vue-start-server 1.167.35 → 1.167.36 Dependent

@nx-cloud

nx-cloud Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 61d058f

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 10m 54s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 29s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-22 06:10:56 UTC

@pkg-pr-new

pkg-pr-new Bot commented Aug 21, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@8145

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8145

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8145

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@8145

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8145

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@8145

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@8145

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8145

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@8145

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@8145

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@8145

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@8145

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@8145

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@8145

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@8145

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@8145

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@8145

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@8145

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8145

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@8145

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8145

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@8145

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8145

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8145

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@8145

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@8145

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@8145

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@8145

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8145

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@8145

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@8145

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8145

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@8145

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@8145

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8145

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@8145

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8145

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8145

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@8145

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@8145

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@8145

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@8145

commit: 61d058f

@codspeed-hq

codspeed-hq Bot commented Aug 21, 2026

Copy link
Copy Markdown

Merging this PR will regress 8 benchmarks

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 8 improved benchmarks
❌ 8 regressed benchmarks
✅ 164 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem client unique-location-churn (solid) 265.7 KB 643.2 KB -58.69%
Memory mem server error-paths redirect (solid) 382.2 KB 659.7 KB -42.06%
Memory mem client navigation-churn (solid) 592.5 KB 707.5 KB -16.24%
Memory mem client unique-location-churn (vue) 467.7 KB 523.6 KB -10.68%
Memory mem server peak-large-page (vue) 1 MB 1.1 MB -10.68%
Memory mem client interrupted-navigations (vue) 368.7 KB 394.4 KB -6.52%
Memory mem server error-paths unmatched (solid) 559.8 KB 588.1 KB -4.81%
Memory mem server server-fn-churn (react) 378.9 KB 393.5 KB -3.72%
Memory mem server error-paths not-found (vue) 2,304.3 KB 481.3 KB ×4.8
Memory mem server error-paths unmatched (react) 544.1 KB 487.4 KB +11.63%
Memory mem server aborted-requests (vue) 1,110.1 KB 1,013.7 KB +9.52%
Memory mem server error-paths not-found (react) 423.7 KB 401.2 KB +5.62%
Memory mem server serialization-payload (vue) 4.5 MB 4.3 MB +4.79%
Memory mem server peak-large-page (react) 1.2 MB 1.2 MB +4.5%
Memory mem client navigation-churn (vue) 1.6 MB 1.6 MB +4.11%
Memory mem server request-churn (vue) 848.2 KB 816.6 KB +3.87%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/task4-parallel-head-scripts (61d058f) with main (d83a896)

Open in CodSpeed

@Sheraff

Sheraff commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #8151, which contains only the route asset parallelization. The independent byte-reduction changes were split into #8150. Both target main.

@Sheraff Sheraff closed this Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant