Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speedup
find_dead_code
pass in control flow analysis (#2159)
Fix slow `find_dead_code` pass in control flow analysis While waiting for the tests to pass on a PR I thought I'd have a quick look to see if I could find any quick wins for dead code analysis #1952. I noticed that that we're using `has_path_connecting` for every combination of node and entry point. This means we were re-checking the same nodes many, many times, searching from scratch each time and not re-using any of the knowledge of already visited nodes in each consecutive traversal. This commit refactors the approach to first collect all known live nodes into a set by traversing from the entry points. We re-use the same `Dfs` when searching from each entry in order to re-use its inner set of visited nodes and avoid re-searching sections of the graph that we've already visited. The dead nodes are those not contained in the live set after traversal. This reduces the time taken within the `find_dead_code` call when building the `std` library in debug from ~7.9 seconds down to ~3.3 milliseconds. 1000x+ speedup in DCA :) Hopefully this speeds up our CI a bit! Closes #1952.
- Loading branch information