turbopack-core: return chunk group kinds instead of cloned chunk groups from ChunkGroupInfo lookups (#102162)
### What?
`ChunkGroupInfo`'s lookups no longer return copies of whole chunk
groups:
- `get_chunk_groups_for_module` and `get_shared_merged_chunk_group`
return a `ChunkGroupSummary`: the chunk group's index and its
`ChunkGroupKind`, which is a `ChunkGroup` without its entry modules.
- `get_async_loader_ancestor_chunk_groups` returns only the chunk group
indices.
The full `ChunkGroup` can still be read by index from
`ChunkGroupInfo::chunk_groups`.
### Why?
`get_chunk_groups_for_module` cloned every chunk group that contains the
module and kept the copies in its cached result. That includes the entry
module lists of `Entry`, `SharedMultiple`, `IsolatedMerged` and
`SharedMerged` groups. In an app with many routes, a shared module is
part of hundreds of chunk groups, so every client reference that was
looked up held a copy of each of them.
The callers (the client reference chunking in next-core, and the server
utility group lookup in next-api) only use the index, the async loader
module of `Async` groups, and the parent and merge tag of the merged
groups.
On a large internal app with about 1,500 routes, in cold `next build
--experimental-build-mode=compile` builds:
| | before | after |
|---|---|---|
| Live heap at the end of the build | 6.06 / 6.11 GiB | 5.87 / 5.98 GiB
|
| Live heap held by the chunk group lookups | 156 / 157 MiB | 18 / 19
MiB |
| Of which cloned `ChunkGroup`s | 128 / 120 MiB | 1.5 / 2.0 MiB |
These are two runs per arm, run alternately, measured with a sampling
heap profiler. An app with about 300 routes held only about 9 MiB of
such clones.
### Verification
- `cargo nextest r -p turbopack-core -p next-core -p next-api`. The only
failures are `resolve::` and `nft` tests that also fail on canary
locally, on macOS.
- `pnpm test-dev-turbo` and `pnpm test-start-turbo`:
`test/e2e/app-dir/rsc-basic`, `test/e2e/app-dir/dynamic`,
`test/e2e/app-dir/app-css`