[turbopack] Compute transitive side effects and use them to trim imports (#86675)
Use our new side effects analysis to statically analyze modules and integrate this into the `remove unused imports` (aka Inner Graph Tree Shaking) logic.
If a module and its transitive dependencies have no side effects based on either declarations or static analysis then we can drop all 'ModuleEvaluation' imports. This can enhance tree shaking and bundle optimization.
From a performance perspective this risky since we need to compute transitive side effects prior to trimming edges. That task is just aggregating a bunch of cached turbo tasks but it might still be expensive. On the other hand trimming edges will speed up chunking and code generation as we have less code to process. To see how this shakes out i built `vercel-site` both ways.
```
~/projects/front/apps/vercel-site (main *)$ hyperfine -p 'rm -rf .next' -w 2 -r 10 'TURBOBPACK_REMOVE_UNUSED_SIDE_EFFECTS=1 pnpm next build --turbopack --experimental-build-mode=compile' 'TURBOBPACK_REMOVE_UNUSED_SIDE_EFFECTS=0 pnpm next build --turbopack --experimental-build-mode=compile'
Benchmark 1: TURBOBPACK_REMOVE_UNUSED_SIDE_EFFECTS=1 pnpm next build --turbopack --experimental-build-mode=compile
Time (mean ± σ): 46.122 s ± 1.453 s [User: 316.651 s, System: 48.030 s]
Range (min … max): 43.149 s … 48.129 s 10 runs
Benchmark 2: TURBOBPACK_REMOVE_UNUSED_SIDE_EFFECTS=0 pnpm next build --turbopack --experimental-build-mode=compile
Time (mean ± σ): 45.864 s ± 1.754 s [User: 321.621 s, System: 48.937 s]
Range (min … max): 44.629 s … 50.647 s 10 runs
Summary
TURBOBPACK_REMOVE_UNUSED_SIDE_EFFECTS=0 pnpm next build --turbopack --experimental-build-mode=compile ran
1.01 ± 0.05 times faster than TURBOBPACK_REMOVE_UNUSED_SIDE_EFFECTS=1 pnpm next build --turbopack --experimental-build-mode=compile
```
So definitely a performance regression, I am adding a new 'global summary' task in the critical path
But how much does it save?
The number of unused references for `vercel-site` goes from 2144 to 21925 (!!), but these are mostly just trimming our parallel `Evaluation` edges, the real idea is number of trimmed modules which goes from 1802 -> 2165 (out of 48783 total) which is a nice if small win. From scanning the names these are mostly icons and date time helper modules.
We do tend to see large wins on benchmarks due to silly patterns they have.