Turbopack: resolve per-module data once during module graph construction (#94842)
### Why
Several passes over the module graph need a per-module property: async
module info, side-effect analysis, module merging, module ids, server
actions, NFT, and build feature telemetry. Each one got it by calling a
turbo-tasks function (`ident()`, `is_self_async()`, `side_effects()`,
`is_mergeable()`, `ident().to_string()`) on every module in the graph.
Each of those calls adds a child edge from the pass's task to the
module's task, so every pass ends by connecting tens of thousands of
children, and those connects are expensive. On `canary`,
`project_feature_usage` alone connects 92k children: 14.6s of CPU that
occupies all 14 worker threads for 1.3s, just after all entrypoints are
written.
### What
The module graph resolves these values once, while it is built, and
stores them per graph. The passes read them from the graph instead of
calling into every module.
- `ident` and `is_self_async` are always collected. `ident_string`,
`side_effects` and `is_mergeable` are only collected when the pass that
needs them runs, via new `ModuleGraphOptions` bits. A pass on a graph
built without its bit fails rather than silently falling back to
per-module calls.
- The values are resolved inline during graph construction, not in a
task per module, and graph nodes stay the same size as on `canary`.
### Performance
Measured on a large internal app (`next build
--experimental-build-mode=compile`, persistent cache on, release
binaries) against the `canary` commit this is based on. Five rounds
after a discarded warmup, alternating which side runs first; each round
runs a cold build and then a warm build. "Paired Δ" compares the two
sides within the same round.
**Cold builds**
| metric | canary | this | Δ mean | paired Δ, median [min, max] |
| ------- | --------------- | --------------- | ------ |
--------------------------- |
| wall | 85.0 ± 1.6s | 76.4 ± 0.3s | −10.1% | −10.2% [−11.5%, −8.0%] |
| user | 598 ± 5s | 574 ± 2s | −4.0% | −3.9% [−4.5%, −3.2%] |
| sys | 102 ± 6s | 67 ± 2s | −34.6% | −34.8% [−39.2%, −31.4%] |
| max RSS | 19.9 ± 0.6 GiB | 20.0 ± 0.1 GiB | +0.7% | −0.4% [−1.8%,
+6.0%] |
**Warm builds**
| metric | canary | this | Δ mean | paired Δ, median [min, max] |
| ------- | --------------- | --------------- | ------ |
--------------------------- |
| wall | 31.7 ± 0.3s | 32.1 ± 0.7s | +1.4% | +0.2% [−0.6%, +6.4%] |
| user | 60.4 ± 0.7s | 59.6 ± 1.9s | −1.3% | +0.1% [−6.8%, +1.7%] |
| sys | 31.2 ± 0.5s | 31.8 ± 1.8s | +2.2% | −0.5% [−4.4%, +13.5%] |
| max RSS | 7.63 ± 0.02 GiB | 7.62 ± 0.06 GiB | −0.1% | −0.4% [−1.4%,
+1.1%] |
Cold builds are faster in every round. Warm builds and memory are
unchanged.
`project_feature_usage` drops from 1.73s to 0.15s in a traced cold build
Incremental rebuilds are also unchanged: over 10 rebuilds that each add
an import to the root layout, rebuild times match, and the persistent
cache grows by 0.49 GiB here vs 0.58 GiB on `canary` (two sequences
each). This makes sense, the ResolvedVc values are _stable_ and so the
module_graph gets invalidated the same amount as always. It is now
slightly larger which is a small concern.
These numbers were measured at the second commit. The third (moving the
data from the nodes into per-graph columns) measured the same within
noise.
<!-- NEXT_JS_LLM_PR -->
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>