[PR #984] [MERGED] perf: fuse RSC stream tees reducing allocs from 3 to 2 #1003

Closed
opened 2026-05-06 13:11:30 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/984
Author: @Divkix
Created: 4/30/2026
Status: Merged
Merged: 5/1/2026
Merged by: @james-elicx

Base: mainHead: fix/981-fuse-ssr-tees


📝 Commits (4)

  • 5e7d11c perf: fuse RSC stream tees reducing allocs from 3 to 2
  • 25ed8cb fix: address PR review feedback for fused RSC stream tees (#981)
  • 626b591 fix: repair CSP nonce handling and update snapshots for #981
  • 8b081e9 Merge origin/main into fix/981-fuse-ssr-tees - resolve app-page-render.ts conflict

📊 Changes

10 files changed (+227 additions, -41 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+6 -2)
📝 packages/vinext/src/server/app-page-execution.ts (+11 -8)
📝 packages/vinext/src/server/app-page-render.ts (+16 -4)
📝 packages/vinext/src/server/app-page-stream.ts (+15 -3)
📝 packages/vinext/src/server/app-ssr-entry.ts (+26 -3)
📝 packages/vinext/src/server/app-ssr-stream.ts (+22 -0)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+36 -12)
📝 tests/app-page-execution.test.ts (+20 -6)
📝 tests/app-page-render.test.ts (+22 -1)
📝 tests/app-ssr-stream.test.ts (+53 -2)

📄 Description

Fixes #981

Summary

  • Fuse Tee 1 (ISR RSC capture) and Tee 2 (SSR embed) into a single stream.tee() call, reducing from 3 tees to 2 in the ISR cache path
  • createRscEmbedTransform now accumulates raw Uint8Array chunks alongside decoded text, exposed via getRawBuffer()
  • teeAppPageRscStreamForCapture returns {ssrStream, sideStream} — sideStream feeds both embed transform and byte accumulation
  • handleSsr accepts optional sideStream + capturedRscDataRef out-parameter, skipping internal tee when pre-split
  • ~33% less ReadableStream objects per ISR request, reducing GC pressure on Cloudflare Workers (128MB limit)

Test plan

  • New tests for createRscEmbedTransform raw buffer accumulation (app-ssr-stream.test.ts)
  • Updated tests for fused teeAppPageRscStreamForCapture returning ssrStream/sideStream (app-page-execution.test.ts)
  • Updated test mock to handle capturedRscDataRef out-param (app-page-render.test.ts)
  • 6 snapshot updates for generated entry template changes (entry-templates.test.ts)
  • 489 related tests pass across 10 test files

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/984 **Author:** [@Divkix](https://github.com/Divkix) **Created:** 4/30/2026 **Status:** ✅ Merged **Merged:** 5/1/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/981-fuse-ssr-tees` --- ### 📝 Commits (4) - [`5e7d11c`](https://github.com/cloudflare/vinext/commit/5e7d11cd101ad0879abae7959bdb91d689b47593) perf: fuse RSC stream tees reducing allocs from 3 to 2 - [`25ed8cb`](https://github.com/cloudflare/vinext/commit/25ed8cb9cde9f0f0350293986fe0a0b5efac54e5) fix: address PR review feedback for fused RSC stream tees (#981) - [`626b591`](https://github.com/cloudflare/vinext/commit/626b591046342151d611a764269269440f8b85c4) fix: repair CSP nonce handling and update snapshots for #981 - [`8b081e9`](https://github.com/cloudflare/vinext/commit/8b081e941c2bcdf83a613c2f5820e0c7d195738b) Merge origin/main into fix/981-fuse-ssr-tees - resolve app-page-render.ts conflict ### 📊 Changes **10 files changed** (+227 additions, -41 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+6 -2) 📝 `packages/vinext/src/server/app-page-execution.ts` (+11 -8) 📝 `packages/vinext/src/server/app-page-render.ts` (+16 -4) 📝 `packages/vinext/src/server/app-page-stream.ts` (+15 -3) 📝 `packages/vinext/src/server/app-ssr-entry.ts` (+26 -3) 📝 `packages/vinext/src/server/app-ssr-stream.ts` (+22 -0) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+36 -12) 📝 `tests/app-page-execution.test.ts` (+20 -6) 📝 `tests/app-page-render.test.ts` (+22 -1) 📝 `tests/app-ssr-stream.test.ts` (+53 -2) </details> ### 📄 Description Fixes #981 ## Summary - Fuse Tee 1 (ISR RSC capture) and Tee 2 (SSR embed) into a single `stream.tee()` call, reducing from 3 tees to 2 in the ISR cache path - `createRscEmbedTransform` now accumulates raw `Uint8Array` chunks alongside decoded text, exposed via `getRawBuffer()` - `teeAppPageRscStreamForCapture` returns `{ssrStream, sideStream}` — sideStream feeds both embed transform and byte accumulation - `handleSsr` accepts optional `sideStream` + `capturedRscDataRef` out-parameter, skipping internal tee when pre-split - ~33% less ReadableStream objects per ISR request, reducing GC pressure on Cloudflare Workers (128MB limit) ## Test plan - New tests for `createRscEmbedTransform` raw buffer accumulation (`app-ssr-stream.test.ts`) - Updated tests for fused `teeAppPageRscStreamForCapture` returning `ssrStream`/`sideStream` (`app-page-execution.test.ts`) - Updated test mock to handle `capturedRscDataRef` out-param (`app-page-render.test.ts`) - 6 snapshot updates for generated entry template changes (`entry-templates.test.ts`) - 489 related tests pass across 10 test files --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:30 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#1003
No description provided.