E0401 (import-error) checks perform repeated _has_init and stat calls #9613
Labels
Enhancement ✨
Improvement to a component
Needs astroid update
Needs an astroid update (probably a release too) before being mergable
performance
Bug description
In astroid, there's a
_has_init
function that looks for the presence of__init__.pyi
,__init__.py
, and other__init__.*
files in a directory.https://github.com/pylint-dev/astroid/blob/098438683cac8d53e67be75856d7d7aab446bb49/astroid/modutils.py#L669-L678
This function is called repeatedly with the same directory arguments. When running pylint on the yt-dlp codebase,
_has_init
ends up performing ~43,000 stats, almost all of which are redundant.Applying a cache to the function brings the number of stats down to ~80 and reduces execution time by ~300ms (~34.1secs -> ~33.8secs).
Configuration
Command used
Steps to reproduce
Analysis
_has_init
callsexists
~43,000 timesPylint output
There may be some import errors depending on your (virtual) environment, but the output is less important than the performance numbers.
Expected behavior
Improved performance via reduced
_has_init
andstat
callsPylint version
OS / Environment
Arch Linux
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: