Skip to content

Commit d3be43d

Browse files
authored
Speed up SCC dependency inference (#18299)
Avoid redundant computation of `frozenset(scc)`. This helps with incremental type checking of torch, since it has a big SCC. In my measurements this speeds up incremental checking of `-c "import torch"` by about 11%.
1 parent be87d3d commit d3be43d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mypy/graph_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def prepare_sccs(
5757
sccs: list[set[T]], edges: dict[T, list[T]]
5858
) -> dict[AbstractSet[T], set[AbstractSet[T]]]:
5959
"""Use original edges to organize SCCs in a graph by dependencies between them."""
60-
sccsmap = {v: frozenset(scc) for scc in sccs for v in scc}
60+
sccsmap = {}
61+
for scc in sccs:
62+
scc_frozen = frozenset(scc)
63+
for v in scc:
64+
sccsmap[v] = scc_frozen
6165
data: dict[AbstractSet[T], set[AbstractSet[T]]] = {}
6266
for scc in sccs:
6367
deps: set[AbstractSet[T]] = set()

0 commit comments

Comments
 (0)