Skip to content

Commit

Permalink
Make CheckUnused not slow. (#20321)
Browse files Browse the repository at this point in the history
It doesn't mean that it's *fast* yet, but it is already a significant
step in that direction. In particular, this goes in the direction of
addressing #19671.

The most important commit is "Simplify the logic for checking unused
imports.", whose commit message follows:

Instead of dealing with entire `tpd.Import`s at the end of the scope, we
eagerly flatten them into individual `ImportSelector`s. We store them
along with some data, including a mutable flag for whether a selector
has been used.

This allows to dramatically simplify `isInImport`, as well as more
aggressively cache the resolution of selectors. We also get rid of the
`IdentityHashMap`.

The algorithm is still `O(n*m)` where n is the number of imports in a
scope, and m the number of references found in that scope. It is not
entirely clear to me whether the previous logic was already `O(n*m)` or
worse (it may have included an additional `p` factor for the number of
possible selections from a given qualifier).

Regardless, it is already quite a bit faster than before, thanks to
smaller constant factors.
  • Loading branch information
sjrd authored May 7, 2024
2 parents 1a62d0a + 8553bfc commit 360d473
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 160 deletions.
Loading

0 comments on commit 360d473

Please sign in to comment.