Inspect module is prohibitively expensive to import
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el comando inspect de tiempo de importación indicado en el issue y revisa el módulo inspect, utilizando la salida de Python's -X importtime para identificar su coste acumulado de importación. Se considera terminado cuando se haya refactorizado inspect para reducir la sobrecarga del tiempo de importación preservando su comportamiento; los PRs enlazados indican que ese trabajo ya está en curso.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- performance
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100