perf(router-core): avoid byte round-trip in SSR stream transform - #8146
perf(router-core): avoid byte round-trip in SSR stream transform#8146Sheraff wants to merge 2 commits into
Conversation
|
View your CI Pipeline Execution ↗ for commit 36e17cc
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version Preview4 package(s) bumped directly, 19 bumped as dependents. 🟩 Patch bumps
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Bundle Size BenchmarksThis pull request does not affect bundle size in any measured scenario. |
There was a problem hiding this comment.
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:
🎓 Learn more about Self-Healing CI on nx.dev
Merging this PR will regress 5 benchmarks
|
Summary
transformStreamWithRouterdecoded every app chunk Uint8Array→string, buffered strings inpendingWrites, and re-encoded at enqueue — two full transcodes per byte even when no router injection happens near the chunk.Uint8Arrayend-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 stringleftover/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 = HoldingTailwas set before the body-prefix emit whose marker scan is gated onstate < 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
</body>scanVerification
RESULT-perf-task5.mdon the branch.