Inspect module is prohibitively expensive to import
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
From post by @AlexWaygood in https://github.com/python/cpython/issues/117372#issuecomment-2047024740_:
I'm a little dismayed that dataclasses adds so much overhead. Does that imply that dataclasses shouldn't be used in the stdlib?
dataclassesis an unfortunately heavy import, yes. Although it imports relatively few modules itself, one of those modules isinspect, which has a huge import time (inspectimports half the standard library). In the past, I've looked into removing thedataclassesdependency oninspect, but couldn't see a way to do so without making the code significantly more ugly; the same goes when it comes to improving the import time forinspectitself. (In hindsight, I'd argueinspectshould probably have been a package rather than a huge single-file Python module... but hindsight is 20/20.)
Perhaps inspect could be refactored to limit the import-time cost.
Currently on my m3 mac pro, on the second attempt, the import times are 1.2ms and 7.9ms (cumulative):
cpython main @ ./python.exe -X importtime -c 'import inspect' 2> /dev/null ; ./python.exe -X importtime -c 'import inspect' 2>1 | grep -E '(cumul|inspect)'
import time: self [us] | cumulative | imported package
import time: 1184 | 7892 | inspect
I've searched the issue tracker and didn't see anything tracking this concern, so right now it's a naïve feature request.
Related: https://github.com/python/cpython/issues/108901
Linked PRs
- gh-119526
- gh-119546
- gh-144756
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 con il comando inspect relativo al tempo di importazione indicato nell’issue ed esamina il modulo inspect, utilizzando l’output di Python's -X importtime per identificare il costo cumulativo delle importazioni. Il lavoro è completato quando inspect è stato sottoposto a refactoring per ridurre l’overhead del tempo di importazione preservandone il comportamento; le PR collegate indicano che il lavoro è già in corso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- performance
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100