ruff
1de944d1 - [ty] Improve flow snapshot performance (#26012)

Commit
27 days ago
[ty] Improve flow snapshot performance (#26012) ## Summary When we build a semantic index, we currently snapshot flow state by eagerly cloning every symbol and member's bindings and declarations at control-flow branches. We also apply scope-wide reachability constraints to every live place immediately, even though most places are unchanged before the branches merge. We now represent snapshots with copy-on-write shared place states and record scope-wide reachability constraints in an append-only parent-linked structure. A place materializes its pending constraints only when it is read or mutated. When both branches still share the same place state, we merge only their path constraints, allowing complementary truthy and falsy paths to cancel without rebuilding the place. The specialized star-import snapshot path remains narrowly scoped and avoids allocating a temporary member list. ## Performance The current [CodSpeed comparison](https://github.com/astral-sh/ruff/pull/26012#issuecomment-4709947650) reports a 6.78% overall improvement, with 12 improved benchmarks and no regressions. DateType improved by 15.51%, anyio by 9.10%, and attrs by 6.96%. CodSpeed notes that some comparisons used different runtime environments, which may affect the exact percentages. The typing-conformance and ecosystem comparisons reported no diagnostic changes, and retained memory was effectively unchanged.
Author
Parents
Loading