refactor(turbopack): chunk several chunk groups in one chunk_group call (#99686)
### What? `ChunkingContext::chunk_group` takes a list of chunk groups and chunks them together, as one chunk group, in a single chunking task. It produces one `ChunkGroupResult` (one `make_chunks` run) for the whole list. `evaluated_chunk_group`, `entry_chunk_group` and the `ChunkingContextExt` helpers still take a single group and wrap it in a one-element list. All existing callers pass a one-element list, so **this PR changes no output** (zero snapshot changes). ### Why? Review feedback on #98734 ([1](https://github.com/vercel/next.js/pull/98734#discussion_r4182977091), [2](https://github.com/vercel/next.js/pull/98734#discussion_r4182978846)): a layout segment's client references can derive several isolated merged chunk groups, and #98734 chunked each one with a separate `chunk_group` call. That costs an extra chunking task per group and threads availability by hand. This PR adds the list form; #98734 then calls `chunk_group` once per segment and side with all of the segment's derived groups. ### How? `make_chunk_group` / `chunk_group_content` / `chunk_group_content_operation` take the list as a `SmallVec<[ChunkGroup; 1]>`: almost every call passes a single group, so the common case doesn't heap-allocate. The list crosses turbo-task boundaries, so this PR also adds `impl TaskInput for SmallVec<A>` in turbo-tasks, mirroring the `Vec` impl. Semantics: - **Traversal:** the entries of each group, in list order, with one shared traversal state. A module already reached from an earlier group isn't collected again, which matches what the previous one-call-per-group sequence produced (CSS order unchanged). - **Availability:** every listed group is added to the resulting availability info. - **Entry groups:** if several `Entry` groups are listed, the active page entries and the resulting entry group are the union of their modules, in list order. - **Edge cases:** an empty list is an error; groups listed more than once (same key) are chunked once. Unit tests cover the edge cases, the `Entry` union, and `SmallVec` as a task input (inline and spilled). This is PR 2 of an eight-PR stack (on top of #99100, already merged): 1. #98733 — canonical chunk-group identity 2. **This PR** — chunk several chunk groups in one `chunk_group` call 3. #99749 — register the chunk groups that are chunked 4. #98734 — use graph-derived merged groups 5. #99750 — chunking takes a `ChunkGroupKey` 6. #98823 — Pages Router dev client graph chaining 7. #98685 — chunk-group availability bitmaps 8. #99050 — keyed chunk-group index lookups <!-- NEXT_JS_LLM --> <!-- fleet 4f67c6f7-bbe2-454b-9a17-822a60ef8f7e --> 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>
Showing
Please
register
or
sign in
to comment