astroid icon indicating copy to clipboard operation
astroid copied to clipboard

Cache _has_init calls to avoid repeated stats

Open correctmost opened this issue 1 year ago • 0 comments

Description

_has_init can end up checking for the presence of the same files over and over.

For example, when running pylint's import-error checks on a codebase like yt-dlp, ~43,000 redundant stats were performed prior to caching.

Closes pylint-dev/pylint#9613.

Performance

I ran pylint with just the import-error checks on the yt-dlp codebase. With pylint-dev/astroid@2c38c0275b790265ab450b79e8dc602e651ca9d3 and pylint-dev/pylint@7521eb1dc6ac89fcf1763bee879d1207a87ddefa, linting takes ~34.1 seconds. With the fix applied, linting takes ~33.8 seconds.

Type of Changes

Type
:hammer: Refactoring

correctmost avatar May 11 '24 22:05 correctmost