Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance by caching find_spec #1

Closed
wants to merge 1 commit into from

Conversation

crazybolillo
Copy link
Owner

@crazybolillo crazybolillo commented Apr 4, 2024

Certain checkers upstream on pylint like import-error heavily use find_spec. This method is IO intensive as it looks for files across several search paths to return a ModuleSpec.

Since imports across files may repeat themselves it makes sense to cache this method in order to speed up the linting process.

Local testing shows that caching reduces the total amount of calls to find_module methods (used by find_spec) by about 50%. Linting the test repository in the related issue goes from 439 to 351 seconds.

Closes pylint-dev/pylint#9310.

@crazybolillo crazybolillo force-pushed the cache-find-spec-crazybolillo branch 3 times, most recently from 4855f7c to 424e57b Compare April 5, 2024 03:36
@codecov-commenter
Copy link

codecov-commenter commented Apr 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.76%. Comparing base (de942f3) to head (424e57b).
Report is 1 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main       #1   +/-   ##
=======================================
  Coverage   92.75%   92.76%           
=======================================
  Files          94       94           
  Lines       11088    11096    +8     
=======================================
+ Hits        10285    10293    +8     
  Misses        803      803           
Flag Coverage Δ
linux 92.57% <100.00%> (+<0.01%) ⬆️
pypy 90.78% <100.00%> (+0.01%) ⬆️
windows 92.39% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
astroid/interpreter/_import/spec.py 97.51% <100.00%> (+0.11%) ⬆️

... and 1 file with indirect coverage changes

Certain checkers upstream on pylint like import-error heavily use
find_spec. This method is IO intensive as it looks for files
across several search paths to return a ModuleSpec.

Since imports across files may repeat themselves it makes sense to cache
this method in order to speed up the linting process.

Local testing shows that caching reduces the total amount of calls to
find_module methods (used by find_spec) by about 50%. Linting the test
repository in the related issue goes from 40 seconds to 37 seconds. This
was on a NVME disk and after warmup, so timing gains may be bigger on
slower file systems like the one mentioned in the referenced issue.

Closes pylint-dev/pylint#9310.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E0401 (import-error) checks perform a lot of repeated stat calls
2 participants