[turbopack] Reduce native React Compiler work (#96820)
## What?
- Use the released `swc_ecma_react_compiler::fast_check::is_required`
API to skip React Compiler work for modules that cannot change in native
`infer` mode.
- Keep explicit `annotation` and `all` modes unconditional.
- Delete Next.js's duplicate React Compiler predicates and use the same
upstream check from the native N-API binding.
- Fail open from the N-API check on unreadable files, fatal parse
failures, and recovered parser errors.
- Keep the client-runtime-only compiler out of App SSR, matching the
existing Babel integration.
- Move the workspace to the coherent SWC 76 dependency family, including
the official `mdxjs-rs-turbopack` branch, with no duplicate SWC 75
stack.
- Keep the React Compiler dependency/module native-only; the WASM facade
already deliberately fails open.
This consumes the implementation landed in
[swc-project/swc#12105](https://github.com/swc-project/swc/pull/12105),
released in `swc_ecma_react_compiler` 23.0.0. Its contract is
conservative: false positives add compiler work, while a negative result
guarantees that compilation cannot alter the program.
## Why?
The native compiler currently runs for every parsed module in infer mode
and is configured for both browser and App SSR contexts. This adds
avoidable AST conversion/compiler work and compiles hydrated client
modules in a server context that the existing Turbopack Babel path
excludes.
This matters for large applications such as v0. Their legacy Babel React
Compiler path creates a separate machine-sized Node worker pool in
addition to PostCSS. Moving to the native path removes that pool; this
patch makes the native path cheaper while preserving the established
browser-only scope.
## Performance
### Upstream fast check on the v0 corpus
The final SWC predicate was checked against 1,816 real v0 modules (10.46
MB):
- selected 302 modules
- retained all 257 modules whose output actually changed
- **zero false negatives**
- scanned the full corpus in 20.624 ms
- reduced the measured full compiler pipeline from 2,371.956 ms to
1,906.180 ms: **-19.64%**
### This Next.js patch only
Real v0 homepage, cold `.next`, Chromium interaction gate, 16 vCPU / 32
GB, exact Next canary `7916855653`, exact v0 commit `1ab042a47c`, three
samples per arm. Both arms use the native compiler.
| Median | Unpatched native | This PR | Change |
|---|---:|---:|---:|
| Visible interactive UI | 50.737 s | 48.574 s | **-4.26%** |
| Network quiet | 70.125 s | 67.546 s | **-3.68%** |
| Aggregate CPU | 450 s | 418 s | **-7.11%** |
| Peak process-tree RSS | 7,904,772 KB | 7,823,008 KB | -1.03% |
All three paired visible, quiet, and CPU deltas favored the patch. The
RSS difference is inside noise, so this PR makes no patch-only memory
claim.
### v0 legacy Babel path to native + this PR
Both arms use `TURBO_ENGINE_EVICT_AFTER_SNAPSHOT=1` and remain open for
120 seconds after network quiet.
| Median | Legacy Babel | Native + this PR | Change |
|---|---:|---:|---:|
| Visible interactive UI | 52.411 s | 48.372 s | **-7.71%** |
| Peak process-tree RSS | 12.19 GiB | 7.39 GiB | **-39.40%** |
| RSS at +120 s | 5.31 GiB | 3.02 GiB | **-43.07%** |
| Aggregate CPU | 480 s | 429 s | **-10.63%** |
| Processes at +120 s | 16 | 4 | **-75.00%** |
The large memory/process delta comes from switching v0 off the external
Babel pool, not from this source diff alone. v0 still needs to enable
the native compiler configuration separately.
Every accepted browser run required HTTP 200, a visible nonblank UI with
at least ten controls, zero Next overlays/page errors, and a verified
prompt interaction. The complete Next process session was sampled every
100 ms.
## Validation
- `cargo fmt --all -- --check`
- affected Rust `cargo check`
- affected Clippy with warnings denied, including Turbopack tests
- React Compiler unit tests: 2 passed
- React Compiler integration tests: 3 passed
- Turbopack snapshots: 114 passed
- direct native N-API/Node smoke: wrapped JSX and member hooks select;
plain modules skip; recovered parse errors and missing files fail open
- dependency trees: native includes `swc_ecma_react_compiler`; WASI
excludes it; no `swc_core` 75 remains
- official `mdxjs-rs-turbopack` SWC 76 bump: 188 tests passed
- final GPT-5.6 Sol + Claude Opus 5 xhigh autoreview: clean, 0.98
confidence from both reviewers
- real-v0 cold browser matrix, 120-second memory soak, and full
production build: 44 Workflow steps / 10 workflows, 2,722/2,722
prerenders
---------
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>