next.js
7086f1bd - bench: add generated large App Router benchmark for Turbopack scaling (#101502)

Commit
4 days ago
bench: add generated large App Router benchmark for Turbopack scaling (#101502) ### What? This adds `bench/large-app-router`, a large generated App Router app. It is meant to be the shared target for measuring how Turbopack `next build` / `next dev` scale with the number of CPU cores (see #100250). - **`scripts/generate.mjs`**: a deterministic generator. A seeded PRNG gives byte-identical output for the same args. It takes `--routes`, `--components` and `--seed`. With the defaults (`--routes 5000 --components 3000`) it writes ~21k files, all gitignored: - 100 sections, each with a layout, `loading.tsx`, `error.tsx` and an index page - 5000 pages: ~10% are `[slug]` segments with `generateStaticParams`, ~15% have nested layouts - a 3000-component shared library, ~35% of it `'use client'`, layered like a design system (primitives → molecules → organisms → templates) - a CSS Module next to every component, layout and page, plus a global stylesheet - imports from `lodash-es`, `lucide-react`, `clsx`, `dayjs` and `zod` (versions already in the lockfile) - `next/dynamic`, plus `import()` in client event handlers - 500 `app/api/*/route.ts` handlers - **`scripts/bench-build.mjs`**: runs N cold `next build`s. It reports per-run wall time and the Turbopack compile time (the `run-turbopack` span from `.next/trace`), plus mean ± sample stddev, with optional JSON output. `--cpus <n>` / `--cpu-list <list>` pin the build via `taskset`, choosing CPUs from the process's allowed affinity. - **README**: covers generate / build / dev / benchmark, using a release next-swc binary, and thread-count control: - `taskset` is recommended, because it limits Node workers too. - `TURBO_TASKS_AVAILABLE_PARALLELISM` sets the Turbopack/tokio thread count. - `TOKIO_WORKER_THREADS` has no effect, because next-swc sets the tokio worker count explicitly. ### Why? The existing `bench/` apps are either small, purely synthetic, or single-purpose. For example, `nested-deps-app-router-many-pages` is 1000 identical template copies with no CSS, route handlers, dynamic imports or npm deps. Scaling work needs one realistic, reproducible, large-enough target. The library is layered on purpose so that every module's transitive closure stays bounded. An unbounded random import graph makes per-page closures grow with the library size, so the total work grows quadratically. Doubling the size then made the compile ~9× slower, which measures the generator rather than the bundler. With the layering, build time grows linearly with app size: 1500 → 3000 routes went from 17.6s → 36.8s of compile at 32 CPUs. ### Initial scaling numbers - **Source:** canary `4d51724b`. **Native binary:** the published release `@next/swc-linux-x64-gnu@16.5.0-canary.46`, loaded via `NEXT_TEST_NATIVE_DIR`. - **App:** default generated size, cold builds with the default persistent cache, 3 runs each, pinned via `--cpus`. > **Topology caveat:** the machine has **16 physical cores / 32 logical CPUs** (SMT, with adjacent siblings). The columns below are *logical* CPUs, so 32 = 16 cores + HT and 16 = 8 cores + HT. This is not yet a curve for 32 physical cores. | Logical CPUs (mask) | `next build` wall | Turbopack compile (`run-turbopack`) | | ------------------- | ----------------: | ----------------------------------: | | 8 (`0-7`) | 168.00s ± 5.38s | 121.98s ± 4.44s | | 16 (`0-15`) | 124.33s ± 2.68s | 89.80s ± 2.75s | | 32 (`0-31`) | 95.34s ± 0.98s | 57.56s ± 0.47s | Speedup of the Turbopack compile: 8 → 16 logical CPUs is 1.36×, 16 → 32 is 1.56×. The parallel efficiency from 8 to 32 is ~53%. Diagnostic: spreading 8 / 16 CPUs across one thread per physical core (`--cpu-list 0,2,4,…`) gave 166.84s ± 6.22s / 121.88s ± 1.93s wall. That is about the same as the SMT-packed masks above, so on this machine adding threads helps about as much as adding physical cores. This was measured on generated output that differs only in the section navigation links. ### How to run ```bash pnpm install && pnpm build cd bench/large-app-router pnpm prepare-bench # or: node scripts/generate.mjs --routes 500 --components 300 for c in 8 16 32; do pnpm bench-build --runs 3 --cpus $c; done ``` ### Verification - The generator is deterministic: two default runs gave the same content hash, a different `--seed` changes the output, and `--routes 100 --components 60` produces 428 files. - Every generated section link resolves to a page or a generated `[slug]` param (5000/5000). - Turbopack `next build` of the default app succeeds on every run above. - `--cpus 4` was confirmed in `/proc/<pid>/status`: the `next-build` process had `Cpus_allowed_list` `0-3`. Invalid, reversed or unavailable CPU lists exit with a clear error. - Prettier and eslint are clean. The lockfile only gains the new importer entry. <!-- NEXT_JS_LLM --> <!-- fleet 844a9209-a191-4c7b-904b-5f0ad1e6b91d --> Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Author
Parents
Loading