next.js
36ad6a3f - turbopack: replace EcmascriptInputTransforms::extend with new/concat turbo tasks (#102010)

Commit
12 hours ago
turbopack: replace EcmascriptInputTransforms::extend with new/concat turbo tasks (#102010) ### What? Replaces `EcmascriptInputTransforms::extend` with two turbo task functions: - `EcmascriptInputTransforms::new(Vec<EcmascriptInputTransform>)`: creates the cell. Being a task function, equal lists share the same cell (interning). - `EcmascriptInputTransforms::concat(Vec<ResolvedVc<EcmascriptInputTransforms>>)`: concatenates lists in order and returns `new(...)`. Callers pass already-resolved cells via `ResolvedVc::deref_vec`, so no resolve call is scheduled. `turbopack/src/lib.rs` (`apply_module_type`, `apply_module_rule_transforms`) now composes the transform lists with a single `concat` call instead of chained `extend` calls. ### Why? Traces showed many `EcmascriptInputTransforms::extend` resolve calls. Chaining `a.extend(b).extend(c)` passes unresolved `Vc`s as `self`, so each step schedules a local resolve task. Each step also produces an intermediate cell that is keyed by input cell identity, not content. ### How? - `concat` reads the parts inside a cached task, so callers depend on one task output per composed list instead of on every input list. - `new` interns by content, so equal final transform lists share one cell, even when they were composed from different input cells. Transform order is preserved. - The value types inside `EcmascriptInputTransform` gain `task_input` so `Vec<EcmascriptInputTransform>` can be a task argument. ### Benchmarks Release bindings. Variants: - **A**: before (`extend` chains) - **B**: `extend` + `.to_resolved().await?` after every call (alternative, not in this PR) - **C**: `new` + `concat` as a plain helper that reads the lists in the caller - **D**: this PR (`new` + cached `concat` task) **`bench/large-app-router`** (default size, Babel enabled for eligible app JS/TS sources), cold `next build`. Instrumented transform-list composition code (one traced run per variant): | | A | C | D | |---|---|---|---| | span self-time, summed across threads | 16.0 s | 11.2 s | 1.8 s | | bytes allocated | 1.75 GB | 290 MB | 37 MB | Span self-time is time inside the named spans, excluding nested spans, summed across all threads, so it is not wall-clock build time. The regions differ: A is the `extend` resolve calls (1.64 M), C the inline helper, D the `concat` call sites. B's caller side wasn't instrumented. Bytes allocated is total allocation inside those spans, not peak memory. **Synthetic app** (about 4.4k modules), compile-only builds: | | A | B | C | D | |---|---|---|---|---| | resolve calls (cold) | 433 k | 291 k | 291 k | 291 k | | task executions (warm, after adding a transform) | 323.8 k | 323.3 k | 313.3 k | 312.6 k | | `analyze_ecmascript_module` executions (same) | 5,419 | 5,417 | 3,764 | 3,760 | C and D re-analyze fewer modules after a transform change, likely because equal transform lists now share a cell. Cold full-build wall times varied in both directions across repeated runs, so no reliable end-to-end speedup was established. ### Verification - `cargo clippy -p turbopack -p turbopack-ecmascript -p next-core --all-targets` - `cargo check -p next-napi-bindings` - `cargo test -p turbopack-tests --test snapshot` (existing tests, unchanged output) - Compile-only emitted output of a synthetic test app is byte-identical to before (excluding caches, traces and random preview keys). <!-- NEXT_JS_LLM --> <!-- fleet 150ea83f-5596-4298-90d9-ea6ec3e81019 --> --------- Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Author
Parents
Loading