next.js
1682685a - Turbopack: replace cssChunking graph `moduleFactorCost` with `weightDistribution` (#95088)

Commit
28 days ago
Turbopack: replace cssChunking graph `moduleFactorCost` with `weightDistribution` (#95088) ## Summary Reworks the cost model of the experimental graph CSS chunking algorithm (`experimental.cssChunking: 'graph'`, Turbopack only) and retunes its defaults. - **Replaces the `moduleFactorCost` option with `weightDistribution`.** The old `moduleFactorCost` term penalized a chunk purely by `chunk_size / group_total_size`, which charged a chunk group even for CSS it fully needs and never actually measured overshipping. - **New per-group cost** is `chunk_group_weight * (chunk_size + request_cost)`, summed over the chunk groups that load a chunk, where `chunk_group_weight = group_total_size ^ (-weightDistribution)` is precomputed once per group. `weightDistribution = 0` weights every chunk group equally; higher values give smaller chunk groups a larger weight, so the algorithm overships less to small pages at the cost of more requests. The size weighting subsumes the explicit overship penalty, so the metric stays chunk-local and the greedy merger is unchanged. - **Retunes defaults:** `requestCost` `20000` → `100000` (bytes) and `weightDistribution` default `0.1`. Config shape (object form): `{ type: 'graph', requestCost?, weightDistribution? }`. The change is wired end to end through the config schema/types, `StyleGroupsAlgorithm::Graph`, and the chunking algorithm. ## Verification - `cargo test -p turbopack-core --lib style_groups_graph` (54 passed, incl. a new test asserting `weightDistribution` keeps an unneeded module out of a small group's chunk) - `pnpm test-start-turbo test/e2e/app-dir/css-order/css-order.test.ts` (243 passed, 12 todo) — confirms chunk shapes/request counts at the new defaults across the `graph` and `graph-object` modes <!-- NEXT_JS_LLM_PR -->
Author
Parents
Loading