Speed up union simplification
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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).
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da make_simplified_union e dal caching dei controlli dei sottotipi in mypy.typestate, quindi esamina le issue correlate #9169, #12408 e #12225. Il lavoro è completo quando la semplificazione delle union è misurabilmente più veloce senza modificarne la semantica, ma l’issue non specifica una singola implementazione o un benchmark.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers, performance
- Tipo di issue
- Refactoring
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100