Speed up union simplification
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Union simplification (make_simplified_union) has been causing multiple performance issues (at least #9169, #12408, #12225). It can make proper subtype checks of all union items against all other items, which is O(n**2) -- with certain O(n) fast paths that cover some (but not all) problematic scenarios. Union simplification is fairly performance-critical even when we don't hit worst-case scenarios.
Here are some ideas about what we might do to improve the situation:
- Somehow implement union simplification of multiple
Instancetypes (at least simple ones) in close to linear time. I suspect that this is possible under some reasonable assumptions. - Cache negative results of proper subtype checks. I think that currently we only cache positive results (in
mypy.typestate). This might have some drawbacks, such as a possible explosion of cache sizes. I assume there's a reason why we aren't currently doing this. Union simplification tends to perform many proper subtype checks with negative results. - Avoid doing full union simplification in some cases, perhaps based on some heuristics. Union simplification should never be semantically necessary.
- Add fast paths for the most common union simplification operations (e.g. single item,
X | None).
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit make_simplified_union und dem Caching der Subtypprüfungen in mypy.typestate, und sieh dir anschließend die zugehörigen Issues #9169, #12408 und #12225 an. Die Arbeit ist abgeschlossen, wenn die Vereinfachung von Unions messbar schneller ist, ohne ihre Semantik zu ändern; das Issue legt jedoch keine einzelne Implementierung oder keinen Benchmark fest.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers, performance
- Issue-Typ
- Refactoring
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100