dillon1000/react
Commit
Browse files Add Flight SSR benchmark fixture (#36180)
This PR adds a benchmark fixture for measuring the performance overhead of the React Server Components (RSC) Flight rendering compared to plain Fizz server-side rendering. ### Motivation Performance discussions around RSC (e.g. #36143, #35125) have highlighted the need for reproducible benchmarks that accurately measure the cost that Flight adds on top of Fizz. This fixture provides multiple benchmark modes that can be used to track performance improvements across commits, compare Node vs Edge (web streams) overhead, and identify bottlenecks in Flight serialization and deserialization. ### What it measures The benchmark renders a dashboard app with ~25 components (16 client components), 200 product rows with nested data (~325KB Flight payload), and ~250 Suspense boundaries in the async variant. It compares 8 render variants: Fizz-only and Flight+Fizz, across Node and Edge stream APIs, with both synchronous and asynchronous apps. ### Benchmark modes - **`yarn bench`** runs a sequential in-process benchmark with realistic Flight script injection (tee + `TransformStream`/`Transform` buffered injection), matching what real frameworks do when inlining the RSC payload into the HTML response for hydration. - **`yarn bench:bare`** runs the same benchmark without script injection, isolating the React-internal rendering cost. This is best for tracking changes to Flight serialization or Fizz rendering. - **`yarn bench:server`** starts an HTTP server and uses `autocannon` to measure real req/s at `c=1` and `c=10`. The `c=1` results provide a clean signal for tracking React-internal changes, while `c=10` reflects throughput under concurrent load. - **`yarn bench:concurrent`** runs an in-process concurrent benchmark with 50 in-flight renders via `Promise.all`, measuring throughput without HTTP overhead. - **`yarn bench:profile`** collects CPU profiles via the V8 inspector and reports the top functions by self-time along with GC pause data. - **`yarn start`** starts the HTTP server for manual browser testing. Appending `.rsc` to any Flight URL serves the raw Flight payload. ### Key findings during development On Node 22, the Flight+Fizz overhead compared to Fizz-only rendering is roughly: - **Without script injection** (`bench:bare`): ~2.2x for sync, ~1.3x for async - **With script injection** (`bench:server`, c=1): ~2.9x for sync, ~1.8x for async - **Edge vs Node** adds another ~30% for sync and ~10% for async, driven by the stream plumbing for script injection (tee + `TransformStream` buffering) The async variant better represents real-world applications where server components fetch data asynchronously. Its lower overhead reflects the fact that Flight serialization and Fizz rendering can overlap with I/O wait times, making the added Flight cost a smaller fraction of total request time. The benchmark also revealed that the Edge vs Node gap is negligible for Fizz-only rendering (~1-2%) but grows to ~15% for Flight+Fizz sync even without script injection. With script injection (tee + `TransformStream` buffering), the gap roughly doubles to ~30% for sync. The async variants show smaller gaps (~5% without, ~10% with injection).
Changed paths39 files
First-parent comparisonfixtures/flight-ssr-bench/README.md AddedA fixtures/flight-ssr-bench/bench-server.js AddedA fixtures/flight-ssr-bench/bench.js AddedA fixtures/flight-ssr-bench/package.json AddedA fixtures/flight-ssr-bench/print-helpers.js AddedA fixtures/flight-ssr-bench/render-helpers.js AddedA fixtures/flight-ssr-bench/rsc-client-ref-loader.js AddedA fixtures/flight-ssr-bench/src/App.js AddedA fixtures/flight-ssr-bench/src/AppAsync.js AddedA fixtures/flight-ssr-bench/src/components/ActivityFeed.js AddedA fixtures/flight-ssr-bench/src/components/ActivityItem.js AddedA fixtures/flight-ssr-bench/src/components/Avatar.js AddedA fixtures/flight-ssr-bench/src/components/Badge.js AddedA fixtures/flight-ssr-bench/src/components/ChartPanel.js AddedA fixtures/flight-ssr-bench/src/components/Dashboard.js AddedA fixtures/flight-ssr-bench/src/components/DashboardAsync.js AddedA fixtures/flight-ssr-bench/src/components/Footer.js AddedA fixtures/flight-ssr-bench/src/components/FooterLink.js AddedA fixtures/flight-ssr-bench/src/components/Header.js AddedA fixtures/flight-ssr-bench/src/components/NavLink.js AddedA fixtures/flight-ssr-bench/src/components/NotificationBell.js AddedA fixtures/flight-ssr-bench/src/components/Pagination.js AddedA fixtures/flight-ssr-bench/src/components/ProductTable.js AddedA fixtures/flight-ssr-bench/src/components/SearchBar.js AddedA fixtures/flight-ssr-bench/src/components/Shell.js AddedA fixtures/flight-ssr-bench/src/components/Sidebar.js AddedA fixtures/flight-ssr-bench/src/components/SidebarSection.js AddedA fixtures/flight-ssr-bench/src/components/Skeleton.js AddedA fixtures/flight-ssr-bench/src/components/StatCard.js AddedA fixtures/flight-ssr-bench/src/components/StatsGrid.js AddedA fixtures/flight-ssr-bench/src/components/TableHeader.js AddedA fixtures/flight-ssr-bench/src/components/TableRow.js AddedA fixtures/flight-ssr-bench/src/components/ThemeProvider.js AddedA fixtures/flight-ssr-bench/src/components/data.js AddedA fixtures/flight-ssr-bench/src/entry-rsc.js AddedA fixtures/flight-ssr-bench/webpack-mock.js AddedA fixtures/flight-ssr-bench/webpack.config.js AddedA fixtures/flight-ssr-bench/yarn.lock AddedM package.json ModifiedPatch
Files changed
Rendering syntax-highlighted changes…