Skip to content

Turbopack: refactor side effects optimization #82466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 8, 2025

Conversation

sokra
Copy link
Member

@sokra sokra commented Aug 8, 2025

What?

Refactors the side effects optimization.

  • Gets rid of the <module evaluation> and the <exports> module.
  • Only two modules: <local> and the facade.
  • The local module has all the evaluation side effects and local exports.
  • The facade reexports the local module and all reexports of the module.
  • require() and import * will resolve to the facade module
  • import "..." will resolve to the locals
  • import { x } from "..." will follow reexports and finally imports from a locals module

Closes PACK-5203

@ijjk ijjk added created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js. labels Aug 8, 2025
Copy link
Member Author

sokra commented Aug 8, 2025

@sokra sokra changed the base branch from sokra/add-side-effects-test-case to graphite-base/82466 August 8, 2025 08:57
@sokra sokra changed the title refactor side effects optimization Turbopack: refactor side effects optimization Aug 8, 2025
Copy link

codspeed-hq bot commented Aug 8, 2025

CodSpeed Performance Report

Merging #82466 will improve performances by 4.52%

Comparing sokra/refactor-side-effects-optimization (ac71779) with canary (8f8c78e)

Summary

⚡ 1 improvements
✅ 8 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
build[lucide-react-all] 9.6 s 9.2 s +4.52%

@sokra sokra marked this pull request as ready for review August 8, 2025 09:30
@sokra sokra requested a review from mischnic August 8, 2025 09:30
@sokra sokra force-pushed the graphite-base/82466 branch from 6441f50 to 8149991 Compare August 8, 2025 11:18
@sokra sokra force-pushed the sokra/refactor-side-effects-optimization branch from fc0bb56 to 9e3cf69 Compare August 8, 2025 11:18
@graphite-app graphite-app bot changed the base branch from graphite-base/82466 to sokra/add-side-effects-test-case August 8, 2025 11:18
@sokra sokra force-pushed the sokra/refactor-side-effects-optimization branch from 9e3cf69 to 2fb7903 Compare August 8, 2025 11:18
Copy link

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments:

turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/locals/module.rs (lines 50-50):

The code calls removed helper function ModulePart::locals() which will cause compilation failure.

View Details

Analysis

The helper function ModulePart::locals() was removed from the ModulePart implementation in turbopack-core/src/resolve/mod.rs, but this call site was not updated. The function previously returned ModulePart::Locals, so this call should be replaced with the direct enum variant.

This will prevent the code from compiling since the function no longer exists.


Recommendation

Replace ModulePart::locals() with ModulePart::Locals.


turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs (lines 342-342):

The code calls removed helper function ModulePart::exports() which will cause compilation failure.

View Details

Analysis

The helper function ModulePart::exports() was removed from the ModulePart implementation in turbopack-core/src/resolve/mod.rs, but this call site was not updated. The function previously returned ModulePart::Exports, so this call should be replaced with the direct enum variant.

This will prevent the code from compiling since the function no longer exists.


Recommendation

Replace ModulePart::exports() with ModulePart::Exports in the part_dep(ModulePart::exports()) call.

@sokra sokra changed the base branch from sokra/add-side-effects-test-case to graphite-base/82466 August 8, 2025 11:36
@sokra sokra force-pushed the graphite-base/82466 branch from 8149991 to 8f8c78e Compare August 8, 2025 11:37
@sokra sokra force-pushed the sokra/refactor-side-effects-optimization branch from 2fb7903 to 50c0d16 Compare August 8, 2025 11:37
@graphite-app graphite-app bot changed the base branch from graphite-base/82466 to canary August 8, 2025 11:37
@sokra sokra force-pushed the sokra/refactor-side-effects-optimization branch from 50c0d16 to c5ae955 Compare August 8, 2025 11:37
@ijjk
Copy link
Member

ijjk commented Aug 8, 2025

Tests Passed

Comment on lines 282 to +283
) -> Result<Vc<FindExportFromReexportsResult>> {
// TODO why do we need a special case for this?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the discussions in #78047

@sokra sokra force-pushed the sokra/refactor-side-effects-optimization branch from c5ae955 to ac71779 Compare August 8, 2025 13:47
@ijjk ijjk added the tests label Aug 8, 2025
@sokra sokra merged commit 428616e into canary Aug 8, 2025
166 of 169 checks passed
@sokra sokra deleted the sokra/refactor-side-effects-optimization branch August 8, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
created-by: Turbopack team PRs by the Turbopack team. tests Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants