Skip to content

perf(router-core): avoid byte round-trip in SSR stream transform - #8146

Draft
Sheraff wants to merge 2 commits into
mainfrom
perf/task5-stream-byte-passthrough
Draft

perf(router-core): avoid byte round-trip in SSR stream transform#8146
Sheraff wants to merge 2 commits into
mainfrom
perf/task5-stream-byte-passthrough

Conversation

@Sheraff

@Sheraff Sheraff commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • transformStreamWithRouter decoded every app chunk Uint8Array→string, buffered strings in pendingWrites, and re-encoded at enqueue — two full transcodes per byte even when no router injection happens near the chunk.
  • App chunks now stay raw Uint8Array end-to-end: byte-level closing-tag/barrier-marker scanner (safe by construction: closing tags are ASCII; UTF-8 continuation bytes are ≥ 0x80 so ASCII matching/slicing can never split a multi-byte char), growable/compacting byte buffer replacing string leftover/pendingTail, polymorphic output queue (string | Uint8Array). Markers split across written ranges now count too, with overlap re-scan.

Audit catch

Found + fixed a real bug during review: state = HoldingTail was set before the body-prefix emit whose marker scan is gated on state < HoldingTail — if the barrier script and </body> arrived in one chunk, the barrier never lifted and router scripts were dropped. Reordered emit-before-transition + regression test added.

Performance

workload before after delta
full transform, large body passthrough 385 ops/s 423 ops/s +10%
full transform, small body w/ frequent injections 12.4k ops/s 18.9k ops/s +52%
scanner micro: medium chunk boundary scan +60%
~13KB no-</body> scan +57%

Verification

  • test:unit ✅ (1610 pass, 4 new incl. tag-straddling-boundary & multibyte cases) · eslint ✅ · types ✅ · prettier ✅
  • Correctness argument for multibyte/boundary handling detailed in RESULT-perf-task5.md on the branch.

@nx-cloud

nx-cloud Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 36e17cc

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

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

@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

@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: c1fa7a8a-cb62-4298-b419-63a999e1372c

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

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

This pull request does not affect bundle size in any measured scenario.

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud has identified a possible root cause for your failed CI:

We determined this failure is an environment issue rather than a regression from the PR changes. The serve package was not pre-installed and required an on-the-fly npm download, causing the test server to not be ready in time — resulting in a missing element on the prerendered page and a subsequent connection refused error. Our PR's changes are scoped to SSR streaming only and do not affect the SPA static-serving path exercised by these tests.

No code changes were suggested for this issue.

Trigger a rerun:

Rerun CI

Nx Cloud View detailed reasoning on Nx Cloud ↗


🎓 Learn more about Self-Healing CI on nx.dev

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

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 36e17cc

@codspeed-hq

codspeed-hq Bot commented Aug 21, 2026

Copy link
Copy Markdown

Merging this PR will regress 5 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

⚡ 13 improved benchmarks
❌ 5 regressed benchmarks
✅ 162 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem server error-paths error (solid) 978.9 KB 1,207.1 KB -18.91%
Memory mem server request-churn (solid) 712.7 KB 804.6 KB -11.42%
Memory mem server request-churn (react) 662.6 KB 701.3 KB -5.53%
Memory mem server server-fn-churn (react) 378.9 KB 392.5 KB -3.47%
Memory mem client navigation-churn (solid) 592.5 KB 612.3 KB -3.23%
Memory mem server streaming-peak chunked (solid) 30.5 MB 2.2 MB ×14
Memory mem server streaming-peak chunked (vue) 11.2 MB 1.1 MB ×10
Memory mem server streaming-peak chunked (react) 11.1 MB 1.7 MB ×6.6
Memory mem server error-paths not-found (vue) 2,304.3 KB 478.2 KB ×4.8
Memory mem server aborted-requests (solid) 1,277.9 KB 787.2 KB +62.33%
Memory mem server error-paths unmatched (react) 544.1 KB 444.3 KB +22.46%
Memory mem server aborted-requests (react) 855.7 KB 700.3 KB +22.19%
Memory mem server aborted-requests (vue) 1.1 MB 1 MB +6.39%
Simulation ssr server-fn during document ssr (vue) 674.5 ms 635.5 ms +6.13%
Memory mem server error-paths redirect (solid) 382.2 KB 363.7 KB +5.08%
Memory mem server error-paths redirect (vue) 427.7 KB 411.2 KB +4.03%
Memory mem server serialization-payload (vue) 4.5 MB 4.3 MB +3.44%
Memory mem server peak-large-page (react) 1.2 MB 1.2 MB +3.01%

Tip

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


Comparing perf/task5-stream-byte-passthrough (36e17cc) with main (d83a896)

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