Skip to content

perf(router-core): classify simple segments before slicing - #8008

Draft
Sheraff wants to merge 1 commit into
mainfrom
agent/parse-segment-branch-order
Draft

perf(router-core): classify simple segments before slicing#8008
Sheraff wants to merge 1 commit into
mainfrom
agent/parse-segment-branch-order

Conversation

@Sheraff

@Sheraff Sheraff commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • classify $param and $ segments from their boundaries before creating a substring
  • recognize static segments without allocating their segment substring
  • defer substring creation to braced or otherwise complex segment syntax
  • add a direct parser benchmark covering mixed, static, deep-static, and braced paths

Why

parseSegment previously allocated a substring before it knew whether the segment needed complex parsing. Simple params, wildcards, and static segments make up the common route grammar, so classifying them from the original path removes avoidable allocation while keeping one canonical parser.

This PR does not require the separate interpolation cleanup. parseSegment is already used by route-tree processing and other core path operations, so the change is independently useful and mergeable in either order.

Impact

Focused local parser benchmarks, each parsing 10,000 complete paths:

  • mixed static/parameter path: 1.599 ms to 1.180 ms (about 26.2% faster)
  • all-static path: 1.506 ms to 1.338 ms (about 11.2% faster)
  • 32-segment all-static path: 9.508 ms to 9.101 ms (about 4.3% faster)
  • braced-parameter path: 1.994 ms to 1.781 ms (about 10.7% faster)

react-router.minimal changes from 85,919 to 85,938 bytes gzip (+19 bytes; raw +23 bytes).

Validation

  • @tanstack/router-core:test:unit: 105 files / 1,536 tests passed, plus 3 expected failures
  • @tanstack/router-core:test:types: TypeScript 5.6 through 7.0 passed
  • @tanstack/router-core:test:eslint: zero errors (existing warnings remain)
  • focused before/after tests/parseSegment.bench.ts runs
  • react-router.minimal bundle-size scenario on main and this branch
  • git diff --check

@coderabbitai

coderabbitai Bot commented Aug 8, 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: c58bf3fc-a726-4e33-9299-200246a6fdb6

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.

@nx-cloud

nx-cloud Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit b57bc35

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

☁️ Nx Cloud last updated this comment at 2026-08-08 12:42:26 UTC

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 17f8c2bde567
  • Measured at: 2026-08-08T12:30:38.002Z
  • Baseline source: history:c568caf3f376
  • Dashboard: bundle-size history

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

Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 83.92 KiB +19 B (+0.02%) 83.79 KiB 262.63 KiB 72.98 KiB █████████▁▁▁
react-router.full 87.42 KiB +19 B (+0.02%) 87.28 KiB 274.35 KiB 76.04 KiB █████████▁▁▁
solid-router.minimal 33.24 KiB +19 B (+0.06%) 33.11 KiB 96.48 KiB 29.92 KiB █████████▁▁▁
solid-router.full 38.06 KiB +16 B (+0.04%) 37.94 KiB 111.11 KiB 34.26 KiB █████████▁▁▁
vue-router.minimal 49.51 KiB +13 B (+0.03%) 49.39 KiB 138.22 KiB 44.67 KiB █████████▁▁▁
vue-router.full 55.09 KiB +14 B (+0.02%) 54.96 KiB 156.40 KiB 49.61 KiB █████████▁▁▁
react-start.minimal 96.68 KiB +20 B (+0.02%) 96.55 KiB 304.81 KiB 83.74 KiB █████████▁▁▁
react-start.deferred-hydration 97.40 KiB +15 B (+0.02%) 96.56 KiB 306.17 KiB 84.48 KiB █████████▁▁▁
react-start.full 99.85 KiB +18 B (+0.02%) 99.71 KiB 314.52 KiB 86.44 KiB █████████▁▁▁
react-start.rsbuild.minimal 100.01 KiB +14 B (+0.01%) 99.84 KiB 315.35 KiB 86.24 KiB ▁▁▁▆▆▆▆▇▇▇▇█
react-start.rsbuild.minimal-iife 100.42 KiB +12 B (+0.01%) 100.25 KiB 316.29 KiB 86.52 KiB ▁▁▁▆▆▆▆▇▇▇▇█
react-start.rsbuild.full 103.33 KiB +15 B (+0.01%) 103.16 KiB 325.44 KiB 89.01 KiB ▁▁▁▅▅▅▅▇▇▇▇█
solid-start.minimal 45.96 KiB +14 B (+0.03%) 45.83 KiB 137.48 KiB 40.87 KiB █████████▁▁▁
solid-start.deferred-hydration 49.03 KiB +21 B (+0.04%) 45.89 KiB 144.94 KiB 43.72 KiB █████████▁▁▁
solid-start.full 51.04 KiB +21 B (+0.04%) 50.91 KiB 152.87 KiB 45.15 KiB █████████▁▁▁
vue-start.minimal 65.50 KiB +13 B (+0.02%) 65.37 KiB 188.99 KiB 58.31 KiB █████████▁▁▁
vue-start.full 69.30 KiB +16 B (+0.02%) 69.17 KiB 201.26 KiB 61.52 KiB █████████▁▁▁

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.

@pkg-pr-new

pkg-pr-new Bot commented Aug 8, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: b57bc35

@codspeed-hq

codspeed-hq Bot commented Aug 8, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 20.07%

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

⚡ 5 improved benchmarks
❌ 10 (👁 6) regressed benchmarks
✅ 165 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ssr dehydrate rich types (solid) 87.3 ms 99.8 ms -12.54%
Simulation ssr dehydrate plain control (solid) 119.6 ms 129.3 ms -7.56%
Simulation ssr global-mw document (solid) 161.9 ms 169.6 ms -4.55%
Simulation client-async-pipeline navigation loop (react) 38.7 ms 39.9 ms -3.13%
Memory mem server error-paths redirect (solid) 588.2 KB 272.8 KB ×2.2
Memory mem client preload-churn (vue) 776.2 KB 735.7 KB +5.5%
Memory mem client interrupted-navigations (vue) 499.5 KB 480.6 KB +3.92%
Memory mem client navigation-churn (solid) 570.2 KB 549.8 KB +3.71%
Simulation ssr control-flow unmatched 404 (react) 67.2 ms 65.1 ms +3.25%
👁 Memory mem server error-paths not-found (solid) 416.3 KB 793.5 KB -47.53%
👁 Memory mem server error-paths not-found (vue) 318.6 KB 2,182.6 KB -85.4%
👁 Memory mem server streaming-peak chunked (vue) 11.2 MB 13.5 MB -17.09%
👁 Memory mem server error-paths not-found (react) 256.3 KB 266.2 KB -3.73%
👁 Memory mem server error-paths unmatched (react) 263.6 KB 602 KB -56.21%
👁 Memory mem client unique-location-churn (solid) 341.6 KB 498.5 KB -31.47%

Tip

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


Comparing agent/parse-segment-branch-order (b57bc35) with main (c568caf)

Open in CodSpeed

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