Files
Luke SandbergandGitHub c54eda4baa [turbopack] Mark packages as side effect free when local analysis determines that they are. (#86398)
This implements some simple static analysis to determine if modules are side effect free based on their top level module evaluation items.

The rules are simple
 * declarations ✅ 
 * literals ✅ 
 * property access ✅  (potentially controversal but consistent with other bundlers)
 * function calls ❌  (unless part of an builtin allowlist, e.g. `Object.keys`)

imports are obviously the difficult part, for that reason we can evaluate a module to `SideEffectful` `SideEffectFree` or `ModuleEvaluationIsSideEffectFree`.  A later step will leverage a graph analysis step to determine of transitive dependencies of ModuleEvaluationIsSideEffectFree modules are also side effect free and upgrade it.

So for right now the impact is minor.  There is also an experimental option to disable it in case it causes trouble this can help us debug

I tested the performance on vercel site and as expected it isn't really observable

with side effect analysis disabled
```
~/projects/front/apps/vercel-site (main *)$ hyperfine -p 'rm -rf .next' -w 2 -r 20  'pnpm next build --turbopack --experimental-build-mode=compile'
Benchmark 1: pnpm next build --turbopack --experimental-build-mode=compile
  Time (mean ± σ):     48.017 s ±  1.696 s    [User: 319.651 s, System: 44.273 s]
  Range (min … max):   44.855 s … 50.600 s    20 runs
```

With it enabled.
```
~/projects/front/apps/vercel-site (main *)$ hyperfine -p 'rm -rf .next' -w 2 -r 20  'pnpm next build --turbopack --experimental-build-mode=compile'
Benchmark 1: pnpm next build --turbopack --experimental-build-mode=compile
  Time (mean ± σ):     48.038 s ±  2.337 s    [User: 320.261 s, System: 45.434 s]
  Range (min … max):   44.156 s … 52.774 s    20 runs
```

so if there is a regression it is well within the noise.
2025-12-11 22:22:38 -08:00

4 lines
28 B
JSON