From 7e79c4a51c253bc8619b698f110d1782db4b9ff8 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Wed, 18 Dec 2024 02:18:30 +0000 Subject: [PATCH] Micro-optimize cache deserialization (fixup) (#18303) Mypyc is bad at compiling tuple unpacking, so this should be faster, based on a microbenchmark I created. Also fewer tuple objects need to be allocated and freed. The impact is probably too small to be measured in a real workload, but every little helps. --- mypy/fixup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/fixup.py b/mypy/fixup.py index f2b5bc17d32e3..1117b5a9ced3f 100644 --- a/mypy/fixup.py +++ b/mypy/fixup.py @@ -117,7 +117,8 @@ def visit_type_info(self, info: TypeInfo) -> None: # NOTE: This method *definitely* isn't part of the NodeVisitor API. def visit_symbol_table(self, symtab: SymbolTable, table_fullname: str) -> None: # Copy the items because we may mutate symtab. - for key, value in list(symtab.items()): + for key in list(symtab): + value = symtab[key] cross_ref = value.cross_ref if cross_ref is not None: # Fix up cross-reference. value.cross_ref = None