next.js
c15cede5 - Turbopack: compute client reference manifest parts once per reference, not per page (#100443)

Commit
25 days ago
Turbopack: compute client reference manifest parts once per reference, not per page (#100443) ## Summary When Turbopack builds an app's client reference manifests, it builds one per app entry (page). For each client reference a page uses, `build_manifest` recomputed: - the reference's server path; - its client, SSR and RSC module ids (each read goes through the chunking context's id strategy, the module's ident and a keyed module-id map read); - for every JS chunk, its component chunks (the merged chunk's runtime info plus each component chunk's path and file size). None of these depend on the page, and pages usually share most of their client references. So the number of reads grew as pages × references, and with `experimental.turbopackChunking.generateComponentChunks` as pages × references × chunks × component chunks. Every read was also another dependency edge on each page's `build_manifest` task. This PR moves that work into two turbo-tasks functions that are keyed only on page-independent inputs: - `client_reference_ids`: keyed on the client reference module, the client chunking context and the optional SSR chunking context. It returns the server path and the client, SSR and RSC module ids. - `client_chunk_components`: keyed on the chunk and the client-relative path. It returns the chunk's component chunk paths and sizes. Each page's manifest now does one cached read per reference and one per chunk. Values and insertion order are unchanged, so the generated manifests are the same. After an edit, only the tasks whose inputs changed rerun. ## Verification - Compared every `*_client-reference-manifest.js` from full `next build` runs with and without this change. All were byte-identical: - a synthetic 300-page app with 40 client references per page, default config: 302 files; - a 1000-page app with 80 references per page and `turbopackChunking: { generateComponentChunks: true, minComponentChunkSize: 0 }`: 1002 files, including merged-chunk entries. - `next dev`: after editing a client component, the edit shows up in the SSR output and the page's client reference manifest still lists the component. - `cargo clippy -p next-core --all-targets -- -D warnings`, `cargo fmt --check` - Trace counts on the 1000-page app confirm the tasks are shared: 1002 manifests ran `client_reference_ids` 408 times and `client_chunk_components` 402 times. - Rough local timings (one 8-core Linux machine, non-LTO release bindings, `next build --experimental-build-mode=compile`; exploratory, not a validated benchmark): - **Default config:** no measurable end-to-end difference; traced `build_manifest` time drops about 15%. - **Component chunks forced on (`minComponentChunkSize: 0`):** traced `build_manifest` time drops from about 63 s to about 6–8 s. Build wall time drops from about 53.8 s to about 48.5 s (median of 8 interleaved runs). - Not run locally: Edge runtime, persistent-cache rebuilds and the e2e suites (left to CI). <!-- NEXT_JS_LLM --> <!-- fleet 27c4bd4e-c7b6-4b23-85a1-32cf20f0a948 --> --------- Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: ejc3 <ejc3@users.noreply.github.com> Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com> Co-authored-by: Fleet Dev Agent <fleet-dev-agent@users.noreply.github.com>
Author
Parents
Loading