E0401 (import-error) checks perform many isinstance calls when searching for zipimporters #9607
Labels
Astroid
Related to astroid
Enhancement ✨
Improvement to a component
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
performance
Bug description
In astroid, there is a
_get_zipimporters
function that scanssys.path_importer_cache
forzipimporter
finders:The
isinstance
call gets executed ~35 million times when running pylint on the yt-dlp repo. ~32 million of these invocations can be avoided by checking forNone
first:if importer is not None and isinstance(importer, zipimport.zipimporter)
A further optimization would be to reduce the number of times
path_importer_cache
is scanned, but that seems trickier to accomplish.Configuration
Command used
Steps to reproduce
Analysis
_get_zipimporters
callsisinstance
~35 million timesChecking for
None
first seems twice as fast:Pylint 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
isinstance
callsPylint version
OS / Environment
Arch Linux
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: