Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
de17a9b1
Unverified
Commit
de17a9b1
authored
Nov 07, 2024
by
Donny/강동윤
Committed by
GitHub
Nov 07, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(turbopack): Implement skipping of side effect free fragments (#71340)
### What? ### Why? ### How? Closes NEXT- Fixes #
parent
45f3ec08
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
28 additions
and
10 deletions
+28
-10
server_actions.rs
crates/next-api/src/server_actions.rs
+1
-0
ident.rs
turbopack/crates/turbopack-core/src/ident.rs
+7
-3
mod.rs
turbopack/crates/turbopack-core/src/resolve/mod.rs
+8
-1
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+1
-1
reference.rs
...pack-ecmascript/src/side_effect_optimization/reference.rs
+3
-1
asset.rs
...opack/crates/turbopack-ecmascript/src/tree_shake/asset.rs
+3
-1
mod.rs
turbopack/crates/turbopack-ecmascript/src/tree_shake/mod.rs
+3
-1
4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_f95732.js
..._basic-tree-shake_tree-shake-test-1_input_index_f95732.js
+1
-1
4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_f95732.js.map
...ic-tree-shake_tree-shake-test-1_input_index_f95732.js.map
+0
-0
lib.rs
turbopack/crates/turbopack/src/lib.rs
+1
-1
No files found.
crates/next-api/src/server_actions.rs
View file @
de17a9b1
...
...
@@ -313,6 +313,7 @@ async fn parse_actions(module: Vc<Box<dyn Module>>) -> Result<Vc<OptionActionMap
|
ModulePart
::
Exports
|
ModulePart
::
Facade
|
ModulePart
::
Internal
(
..
)
|
ModulePart
::
InternalEvaluation
(
..
)
)
{
return
Ok
(
OptionActionMap
::
none
());
}
...
...
turbopack/crates/turbopack-core/src/ident.rs
View file @
de17a9b1
...
...
@@ -283,15 +283,19 @@ impl AssetIdent {
5
_u8
.deterministic_hash
(
&
mut
hasher
);
id
.deterministic_hash
(
&
mut
hasher
);
}
ModulePart
::
Locals
=>
{
ModulePart
::
InternalEvaluation
(
id
)
=>
{
6
_u8
.deterministic_hash
(
&
mut
hasher
);
id
.deterministic_hash
(
&
mut
hasher
);
}
ModulePart
::
Export
s
=>
{
ModulePart
::
Local
s
=>
{
7
_u8
.deterministic_hash
(
&
mut
hasher
);
}
ModulePart
::
Facade
=>
{
ModulePart
::
Exports
=>
{
8
_u8
.deterministic_hash
(
&
mut
hasher
);
}
ModulePart
::
Facade
=>
{
9
_u8
.deterministic_hash
(
&
mut
hasher
);
}
}
has_hash
=
true
;
...
...
turbopack/crates/turbopack-core/src/resolve/mod.rs
View file @
de17a9b1
...
...
@@ -2929,6 +2929,8 @@ pub enum ModulePart {
RenamedNamespace
{
export
:
Vc
<
RcStr
>
},
/// A pointer to a specific part.
Internal
(
u32
),
/// A pointer to a specific part, but with evaluation.
InternalEvaluation
(
u32
),
/// The local declarations of a module.
Locals
,
/// The whole exports of a module.
...
...
@@ -2968,6 +2970,10 @@ impl ModulePart {
ModulePart
::
Internal
(
id
)
.cell
()
}
#[turbo_tasks
::
function]
pub
fn
internal_evaluation
(
id
:
u32
)
->
Vc
<
Self
>
{
ModulePart
::
InternalEvaluation
(
id
)
.cell
()
}
#[turbo_tasks
::
function]
pub
fn
locals
()
->
Vc
<
Self
>
{
ModulePart
::
Locals
.cell
()
}
...
...
@@ -2999,7 +3005,8 @@ impl ValueToString for ModulePart {
ModulePart
::
RenamedNamespace
{
export
}
=>
{
format!
(
"export * as {}"
,
export
.await
?
)
.into
()
}
ModulePart
::
Internal
(
id
)
=>
format!
(
"internal part {}"
,
id
,)
.into
(),
ModulePart
::
Internal
(
id
)
=>
format!
(
"internal part {}"
,
id
)
.into
(),
ModulePart
::
InternalEvaluation
(
id
)
=>
format!
(
"internal part {}"
,
id
)
.into
(),
ModulePart
::
Locals
=>
"locals"
.into
(),
ModulePart
::
Exports
=>
"exports"
.into
(),
ModulePart
::
Facade
=>
"facade"
.into
(),
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
de17a9b1
...
...
@@ -608,7 +608,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
ImportedSymbol
::
Symbol
(
name
)
=>
Some
(
ModulePart
::
export
((
&**
name
)
.into
())),
ImportedSymbol
::
PartEvaluation
(
part_id
)
=>
{
evaluation_references
.push
(
i
);
Some
(
ModulePart
::
internal
(
*
part_id
))
Some
(
ModulePart
::
internal
_evaluation
(
*
part_id
))
}
ImportedSymbol
::
Part
(
part_id
)
=>
Some
(
ModulePart
::
internal
(
*
part_id
)),
ImportedSymbol
::
Exports
=>
Some
(
ModulePart
::
exports
()),
...
...
turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/reference.rs
View file @
de17a9b1
...
...
@@ -80,7 +80,9 @@ impl ModuleReference for EcmascriptModulePartReference {
|
ModulePart
::
RenamedNamespace
{
..
}
=>
{
Vc
::
upcast
(
EcmascriptModuleFacadeModule
::
new
(
*
self
.module
,
*
part
))
}
ModulePart
::
Export
(
..
)
|
ModulePart
::
Internal
(
..
)
=>
{
ModulePart
::
Export
(
..
)
|
ModulePart
::
Internal
(
..
)
|
ModulePart
::
InternalEvaluation
(
..
)
=>
{
bail!
(
"Unexpected ModulePart {} for EcmascriptModulePartReference"
,
part
.to_string
()
.await
?
...
...
turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs
View file @
de17a9b1
...
...
@@ -166,7 +166,9 @@ impl Module for EcmascriptModulePartAsset {
// This is an internal part that is not for evaluation, so we don't need to
// force-add it.
PartId
::
Internal
(
..
,
false
)
=>
return
None
,
PartId
::
Internal
(
part_id
,
true
)
=>
ModulePart
::
internal
(
*
part_id
),
PartId
::
Internal
(
part_id
,
true
)
=>
{
ModulePart
::
internal_evaluation
(
*
part_id
)
}
PartId
::
Export
(
name
)
=>
ModulePart
::
export
(
name
.clone
()),
_
=>
unreachable!
(
"PartId other than Internal and Export should not be used here"
...
...
turbopack/crates/turbopack-ecmascript/src/tree_shake/mod.rs
View file @
de17a9b1
...
...
@@ -368,7 +368,9 @@ async fn get_part_id(result: &SplitResult, part: Vc<ModulePart>) -> Result<u32>
ModulePart
::
Evaluation
=>
Key
::
ModuleEvaluation
,
ModulePart
::
Export
(
export
)
=>
Key
::
Export
(
export
.await
?
.as_str
()
.into
()),
ModulePart
::
Exports
=>
Key
::
Exports
,
ModulePart
::
Internal
(
part_id
)
=>
return
Ok
(
*
part_id
),
ModulePart
::
Internal
(
part_id
)
|
ModulePart
::
InternalEvaluation
(
part_id
)
=>
{
return
Ok
(
*
part_id
)
}
ModulePart
::
Locals
|
ModulePart
::
Facade
|
ModulePart
::
RenamedExport
{
..
}
...
...
turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/tree-shake-test-1/output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_
af8faa
.js
→
turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/tree-shake-test-1/output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_
f95732
.js
View file @
de17a9b1
(
globalThis
.
TURBOPACK
=
globalThis
.
TURBOPACK
||
[]).
push
([
"output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_
af8faa
.js"
,
"output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_
f95732
.js"
,
{},
{
"otherChunks"
:[
"output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_d79193.js"
],
"runtimeModuleIds"
:[
"[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/tree-shake-test-1/input/index.js [test] (ecmascript)"
]}
]);
...
...
turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/tree-shake-test-1/output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_
af8faa
.js.map
→
turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/tree-shake-test-1/output/4c35f_tests_snapshot_basic-tree-shake_tree-shake-test-1_input_index_
f95732
.js.map
View file @
de17a9b1
File moved
turbopack/crates/turbopack/src/lib.rs
View file @
de17a9b1
...
...
@@ -142,7 +142,7 @@ async fn apply_module_type(
None
};
if
let
Some
((
part
,
_
))
=
part_ref
{
if
let
ModulePart
::
Evaluation
=
&*
part
{
if
let
ModulePart
::
Evaluation
|
ModulePart
::
InternalEvaluation
(
..
)
=
&*
part
{
// Skip the evaluation part if the module is marked as side effect free.
let
side_effect_free_packages
=
module_asset_context
.side_effect_free_packages
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment