Case study · tsx2rs · In progress

Next.js, compiled to Rust. Same output.

A Next.js Deployment Adapter that compiles React server component templates into programs for a native Rust engine. Client components come from an HTML cache, and anything it can't compile falls back to Next.js. Turning it on takes one line of config.

Role
Solo, personal project
Status
In progress, Phase 1
Started
October 2026
Licence
Open source, Apache-2.0

Throughput on a real app

next start

402 ms median

618

tsx2rs prototype

23 ms median

10,218
Requests per second, Vercel Commerce product page, 8 processes on Google Cloud. Hand-compiled prototype; output identical to Next.js.

01The problem

Self-hosted Next.js spends most of its CPU on itself.

Next.js is the default way to build a React app, and many teams run it on their own servers. Three facts shaped the project.

Every page rendered twice

Profiling showed Next.js renders a page to the RSC (Flight) format, decodes it and renders it again to HTML. HTML itself is only about 13% of its CPU; the rest is framework work.

Self-hosters pay the bill

Teams that run Next.js on their own Docker, Kubernetes or VMs pay for every one of those CPU cycles. On Vercel's platform this is someone else's problem; off it, it's yours.

No one gives up features

A faster server that drops streaming, metadata, server actions or client components won't be adopted. It has to be exactly Next.js, with no code changes.

The win isn't Rust on its own. It comes from skipping Next.js's request pipeline for the parts that can be compiled, and handing everything else back to Next.js unchanged.

02How it works

One config line, and Next.js stays in charge.

tsx2rs plugs in through Next.js's official Deployment Adapter API. It routes requests exactly as next start does.

  1. 01

    Compile

    At build time, each page's JSX templates become template programs

  2. 02

    Run setup

    The app's own data-fetching code still runs in Node, unchanged

  3. 03

    Encode

    A generated encoder hands the values to Rust in one call, as compact bytes

  4. 04

    Render

    The Rust engine writes HTML and Flight in a single pass

  5. 05

    Cache islands

    Client components come from an HTML cache; React renders only on a miss

  6. 06

    Fall back

    Anything it can't compile goes to Next.js's own handler

Users never need a Rust toolchain: the compiler emits template programs for one prebuilt engine. If a page can't be served identically, it isn't served by tsx2rs.

03Validate first

Ten experiments before any product code. Each one changed the plan.

I didn't write the product until every open question had a measured answer. This is how the idea changed along the way.

experiments before product code
10
logged decisions
35
architecture records
11
pull requests
29
lines of Rust
10k
  1. Proposal

    Start from a doubt

    The first idea was "zero V8": compile server components to Rust, drop Node and leave client components as empty placeholders. It would have lost Next.js features, so I set one rule: compile what we can and fall back for the rest.

  2. Speed

    Is the idea real?

    A hand-written Rust renderer produced output byte-identical to React, about 10x faster, with a 20 ms cold start instead of 1.6 s. Byte-identical became the correctness rule.

  3. Profile

    Find where the time goes

    Replacing only the HTML step inside Next.js would gain 1.15x. The real ceiling was in bypassing its request handling, which pointed to Next.js 16's new Deployment Adapter API.

  4. Real apps

    Study 606 routes in 13 apps

    Only 8% of routes compile as written, because pages fetch data inside components. Compiling just the returned JSX, and lifting awkward calls out of it, raises that to 92%.

  5. Handoff

    Measure the boundary

    Passing data from JS to Rust as JSON cost five times the render itself. A compiler-generated binary encoder kept Rust 7.3x faster than React end to end.

  6. Cloud

    Prove it on clean machines

    A hand-compiled Vercel Commerce product page, streaming and multi-core runs on Google Cloud: identical output, working in a real browser, 12–17x the throughput of next start.

  7. Now

    Build the product

    The real compiler and engine, in their own open-source repository with CI, differential tests and decision records. The engine side of the current step is done; the compiler side is next.

04Key decisions

Five calls that shaped it.

01/Scope

Compile templates, not components

8 → 92%

routes that can compile

The problem
Real pages fetch their data inside the component. A compiler that needs the whole component to be compilable would cover almost nothing.
What I did
Split every component in two: its setup code stays JavaScript and runs as normal, and only the JSX it returns is compiled. Calls that don't belong in a template are lifted out, keeping their original conditions.
What happened
On the 13-app corpus, coverage went from 8% of routes to 92% (optimistic), without asking anyone to rewrite a page.

02/Islands

Empty placeholders were never an option

74%

of elements are client components

The problem
Every route in the study had client components, a median of 10. Across 12 production pages they made up about 74% of the elements.
What I did
Serve client-component HTML from a cache keyed by component, props and the contexts it reads, and let React render it only on a miss. Their props repeated 94–100% between requests.
What happened
Pages keep their full server-rendered HTML. Even with a 0% cache hit rate the real app stays about 4–5x faster.

03/Boundary

Bytes, not JSON

7.3x

React, with the generated encoder

The problem
Moving data from JS to Rust as JSON cost about five times the render. The obvious conclusion was to drop Rust in the first stage and generate JS templates instead.
What I did
I pushed back and tested one more option: since the compiler knows each template's fields, it can generate a binary encoder that sends only those, with no JSON at all.
What happened
Rust stayed 7.3–7.5x faster than React end to end, and 2.6x the best JS template. Rust stayed in.

04/Correctness

Identical, or fall back

15 / 15

planted bugs caught

The problem
A faster server that changes a single byte of HTML, or one node of the Flight tree, can break hydration in ways nobody notices until production.
What I did
The output must match React and Next.js exactly, using them as test oracles. Differential tests generate random trees, and planted bugs check that the tests would actually catch a mistake.
What happened
20,000 generated trees render identically to React, and every planted bug was caught. When the compiler can't guarantee a match, the request goes to Next.js.

05/Honesty

Correct the claim, not the data

14–19x

less memory per request served

The problem
Laptop runs showed about 4x less memory than Next.js. On clean cloud machines under full load, each process used about as much memory as Next.js.
What I did
Keep the clean-machine run as the reference for every claim, and restate memory per unit of throughput instead of per process.
What happened
The published claim is 14–19x less memory per request served, not a per-process number that doesn't hold under load.

05Results so far

Measured on clean machines.

16.5x

the throughput of next start on a real app, with every core in use

Vercel Commerce's product page, compiled by hand as a stand-in for compiler output, on two Google Cloud c3-standard-8 machines: 10,218 vs 618 requests per second. HTML and Flight were identical to Next.js on all 9 pages tested.

median latency at full load, against 402 ms for next start
23 ms
first byte when streaming Suspense, against 268–883 ms
31 ms
pages identical to Next.js on Linux, HTML and Flight
9 / 9
generated trees identical to React in the product's engine
20,000
of the hand-written prototype's speed, from the real engine
123%+

06Where it stands

Not usable yet. Here's where it is.

Prove the idea is worth building before writing the product.

tsx2rs is not usable yet. The engine reproduces React's output for everything the current milestone needs; the compiler that turns a real page into a program is being built now. The milestone ends when it reproduces the Commerce page by itself, at 90% or more of the hand-written speed.

The headline numbers come from a hand-compiled prototype, and I say so wherever they appear. Every pivot so far came from a measurement rather than a hunch, and each one is written down with its reasoning, so the project can explain itself.

Follow it on GitHub

07Stack

Rust where it counts, Next.js everywhere else.

Compiler & engine
Rustoxcnapi-rscriterion
Runtime & adapter
TypeScriptNode.jsNext.js 16React 19
Testing
Differential testsMutation checksVitestInstruction counts in CI
Benchmarks
Google Cloudohanode:cluster

Let's work together

Building something that has to be exactly right? Let's talk.