Skip to content

Commit

Permalink
Optional parallel merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jan 19, 2025
1 parent 3743722 commit 87d8774
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ impl VisitMut for TreeShaker {
}

fn merge_data(data: Arc<ThreadLocal<RefCell<Data>>>) -> Data {
#[cfg(feature = "concurrent")]
let data = Arc::try_unwrap(data)
.map_err(|_| {})
.unwrap()
Expand All @@ -1218,15 +1219,23 @@ fn merge_data(data: Arc<ThreadLocal<RefCell<Data>>>) -> Data {
.collect::<Vec<_>>();

#[cfg(feature = "concurrent")]
let iter = data.into_par_iter();
let mut merged = data
.into_par_iter()
.reduce(Data::default, |mut merged, data| {
merged.merge(data);
merged
});

#[cfg(not(feature = "concurrent"))]
let iter = data.into_iter();

let mut merged = iter.reduce(Data::default, |mut merged, data| {
merged.merge(data);
merged
});
let mut merged = Arc::try_unwrap(data)
.map_err(|_| {})
.unwrap()
.into_iter()
.map(|d| d.into_inner())
.fold(Data::default(), |mut merged, data| {
merged.merge(data);
merged
});

merged.subtract_cycles();

Expand Down Expand Up @@ -1292,7 +1301,7 @@ impl Merge for Data {
fn merge(&mut self, other: Self) {
self.used_names.merge(other.used_names);
self.entry_ids.extend(other.entry_ids);
// self.edges.0.merge(other.edges.0);
self.edges.0.merge(other.edges.0);
}
}

Expand Down

0 comments on commit 87d8774

Please sign in to comment.