From 7603a3abaccf4681a0a86037378fe4046328db75 Mon Sep 17 00:00:00 2001 From: Jahongir Qurbonov Date: Tue, 10 Nov 2026 09:34:27 +0500 Subject: [PATCH] [mypyc] Only track registers in must-defined analysis The refcount and uninit transforms pass all values, including temporaries, as the universe of the must-defined analysis. The analysis only generates and kills registers, and the callers only check registers, so the temporaries are never needed. However, a must analysis starts with a copy of the universe for every basic block, so time and memory used were O(blocks * values). This made the refcount transform very slow for large functions. For a function with 4000 statements (36k ops, 16k blocks), it took ~110s and used 15 GiB of memory. Now it takes 6s and uses 3.3 GiB. Leave everything except registers out of the universe. The generated IR and C are unchanged. --- mypyc/analysis/dataflow.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mypyc/analysis/dataflow.py b/mypyc/analysis/dataflow.py index babf7fbc6c87d..324706dfb9849 100644 --- a/mypyc/analysis/dataflow.py +++ b/mypyc/analysis/dataflow.py @@ -44,6 +44,7 @@ OpVisitor, PrimitiveOp, RaiseStandardError, + Register, RegisterOp, Return, SetAttr, @@ -386,7 +387,9 @@ def analyze_must_defined_regs( initial=initial_defined, backward=False, kind=MUST_ANALYSIS, - universe=set(regs), + # Only registers can be undefined (temporaries are always defined before use), + # so leave everything else out of the universe to keep the sets small. + universe={r for r in regs if isinstance(r, Register)}, )