Skip to content

perf(turbopack): Optimize turbopack tree shaking using pure #70433

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 3 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions turbopack/crates/turbopack-ecmascript/src/tree_shake/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl DepGraph {
/// performance.
pub(super) fn finalize(
&self,
_data: &FxHashMap<ItemId, ItemData>,
data: &FxHashMap<ItemId, ItemData>,
) -> InternedGraph<Vec<ItemId>> {
let graph = self.g.idx_graph.clone().into_graph::<u32>();

Expand All @@ -584,7 +584,7 @@ impl DepGraph {
let mut new_graph = InternedGraph::default();
let mut done = FxHashSet::default();

let mapped = condensed.map(
let mapped = condensed.filter_map(
|_, node| {
let mut item_ids = node
.iter()
Expand All @@ -596,9 +596,9 @@ impl DepGraph {
.collect::<Vec<_>>();
item_ids.sort();

new_graph.node(&item_ids)
Some(new_graph.node(&item_ids))
},
|_, edge| *edge,
|_, edge| Some(*edge),
);

let map = GraphMap::from_graph(mapped);
Expand All @@ -607,7 +607,12 @@ impl DepGraph {

for node in self.g.graph_ix.iter() {
let ix = self.g.get_node(node);

if !done.contains(&ix) {
if data[node].pure {
continue;
}

let item_ids = vec![node.clone()];
new_graph.node(&item_ids);
}
Expand Down
Loading