Skip to content
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

perf(es/minifier): Make DCE analyzer parallel #9865

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Jan 11, 2025

Description:

The analyzer of the DCE pass can be parallelized in a similar way to mark-sweep GC. It currently uses &mut petgraph::DiGraphMap to find reachable bindings, but we can split the graph creation into multiple threads.

Also, I decided to amort allocations because swc_parallel::join is called an enormous amount of time, meaning that it will be slower if I allocate one hashmap from each closure. I'll use thread_local crate to reuse the hashmap and collect all of them after the traversal is done.

@kdy1 kdy1 added this to the Planned milestone Jan 11, 2025
@kdy1 kdy1 self-assigned this Jan 11, 2025
Copy link

changeset-bot bot commented Jan 11, 2025

⚠️ No Changeset found

Latest commit: 57ff7b8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@kdy1 kdy1 changed the title perf(es/minifier): Make DCE analyzer partially parallel perf(es/minifier): Make DCE analyzer parallel Jan 11, 2025
@kdy1 kdy1 force-pushed the dce-par branch 6 times, most recently from d71bf03 to 593d5e9 Compare January 12, 2025 20:39
@kdy1 kdy1 marked this pull request as ready for review January 13, 2025 07:05
@kdy1 kdy1 requested a review from a team as a code owner January 13, 2025 07:05
@kdy1 kdy1 requested a review from a team as a code owner January 13, 2025 07:05
kodiakhq[bot]
kodiakhq bot previously approved these changes Jan 13, 2025
Copy link
Member Author

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Any ideas to improve the performance even more?

@@ -1111,6 +1203,87 @@ impl VisitMut for TreeShaker {
}
}

fn merge_data(data: Arc<ThreadLocal<RefCell<Data>>>) -> Data {
Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, this function is slow and I want to optimize this function further.

}
};
}
}

/// Traverse the graph and subtract usages from `used_names`.
fn subtract_cycles(&mut self) {
Copy link
Member Author

Choose a reason for hiding this comment

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

But this function call is necessary.

Copy link
Member Author

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Any ideas to improve the performance even more?

@kdy1
Copy link
Member Author

kdy1 commented Jan 13, 2025

I tried profiling, but it seems to have almost no effect on current benchmark suite, which only contains libraries.

DCE is impactful for real-world apps, though.

Copy link

codspeed-hq bot commented Jan 14, 2025

CodSpeed Performance Report

Merging #9865 will not alter performance

Comparing kdy1:dce-par (57ff7b8) with main (197f0bc)

Summary

✅ 196 untouched benchmarks

@kdy1 kdy1 marked this pull request as draft January 14, 2025 23:39
@kdy1
Copy link
Member Author

kdy1 commented Jan 15, 2025

  • Command: ddt profile samply cargo --release --features tracing/release_max_level_off --features concurrent --example minify-all -- ~/projects/minifier-inputs

PR

Using 1970 files
Took 2.278659166s

Main

Using 1970 files
Took 2.087783708s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant