perf(turbopack): look up chunk group indices through a keyed cell (#99050)
### What?
Narrows the turbo-tasks dependency of `ChunkGroupInfo::get_index_of` so
that looking up one chunk group's index no longer depends on the entire
`ChunkGroupInfo`.
This is PR 6 of a six-PR stack, based on `canary` (#98733, #99686 and
#99749 are already merged):
1. #98823 — Pages Router dev client graph chaining
2. #99910 — regression test for Pages Router `_app` availability
(#99789)
3. #98734 — use graph-derived merged groups
4. #99750 — chunking takes a `ChunkGroupKey`
5. #98685 — chunk-group availability bitmaps
6. **This PR** — keyed chunk-group index lookups
### Why?
#98685 makes availability a set of chunk-group *indices*, which turns
`get_index_of` into a hot path: every availability translation between
graphs resolves keys to indices through it.
That lookup previously read `chunk_group_keys` off the whole
`ChunkGroupInfo` value. In turbo-tasks, reading one field of a cell
creates a dependency on the cell as a whole, so every index lookup in
the graph was invalidated whenever *any* unrelated part of the chunk
group info changed — a new async chunk group anywhere in the app re-ran
every lookup, and everything downstream of them. The wider the
availability work built on top of it, the more that costs.
### How?
Adds `ChunkGroupKeyToIndex`, a `cell = "keyed"` map from `ChunkGroupKey`
to its index, alongside the existing set, exposed through an
argument-less `chunk_group_indices()` task. `get_index_of` reads a
single key from it through `Vc::get`, so its caller depends only on the
key it actually asked for: an unrelated chunk group changing no longer
invalidates it.
`get_index_of` itself is deliberately a plain async method rather than a
turbo-tasks function. As a function it would create one task per chunk
group argument, which is exactly the per-chunk-group overhead this
change is meant to remove; the single `chunk_group_indices()` task is
what provides the caching.
The interesting constraint is why this can't reuse the
`FxIndexSet<ChunkGroupKey>` that was already there — a set that already
holds exactly these keys in exactly this order. Two properties of the
keyed-cell traits rule it out:
- `KeyedAccess for IndexSet` yields `()`, not the index, so the value
needed isn't retrievable through a keyed read.
- `KeyedEq for IndexSet` compares *membership* and ignores position. A
key whose index merely shifted — same set, different order — would not
be reported as changed, and lookups would keep returning a stale index.
That is a correctness bug, not just a missed invalidation.
Mapping the key to the index as the *value* makes `KeyedEq for HashMap`
compare indices, which detects exactly that shift. The `FxIndexSet`
stays for the reverse (index → key) direction, so the duplication is
deliberate and documented at the type.
The debug-only "couldn't find chunk group" diagnostic still reads the
whole struct to render its message. That path is only taken on failure,
so the happy path keeps its narrow dependency.
### Verification
Keyed-cell invalidation semantics (per-key dependencies, `KeyedEq`
comparing values) are covered by turbo-tasks' own tests, so this PR does
not add a dedicated invalidation test.
- `cargo clippy --workspace --all-targets -- -D warnings -A deprecated`
- `turbopack-core` + `next-core` — 252 passed
- Turbopack snapshots — 126 passed, no output churn
- `cargo fmt --check` clean
Behavior is unchanged; this is a dependency-graph refactor with no
effect on emitted output.
<!-- 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>