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

Cache requires-python checks & skip debug logging #13128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ichard26
Copy link
Member

The requires-python check is pretty fast, but when performed for 10000 links, the checks consume a nontrival amount of time. For example, while installing (pre-cached + --dry-run) a pared down list of homeassistant dependencies (117 in total), link evaluation took 15% of the total runtime, with check_requires_python() accounting for half (7.5%) of that.

The cache can be kept pretty small as requires-python specifiers often repeat, and when they do change, it's often in chunks (or between entirely different packages). For example, setuptools has like 1500 links, but only ~30 different requires-python specifiers.

In addition, _log_skipped_link() is a hot method and unfortunately expensive as it hashes the link on every call. Fortunately, we can return early when debug logging is not enabled. In the same homeassistant run, this saves 0.7% of the runtime.


Command: python -m cProfile -o profile.pstats -m pip install -r temp/homeassistant/requirements.txt --dry-run

Before

image
image

After

image

The Link.from_json() classmethod is surprisingly expensive. I'll take a look at speeding that up next.

The `requires-python` check is pretty fast, but when performed for
10000 links, the checks consume a nontrival amount of time. For example,
while installing (pre-cached + --dry-run) a pared down list of
homeassistant dependencies (117 in total), link evaluation took 15% of
the total runtime, with  check_requires_python() accounting for half
(7.5%) of that.

The cache can be kept pretty small as `requires-python` specifiers often
repeat, and when they do change, it's often in chunks (or between
entirely different packages). For example, setuptools has like 1500
links, but only ~30 different `requires-python` specifiers.

In addition, _log_skipped_link() is a hot method and unfortunately
expensive as it hashes the link on every call. Fortunately, we can
return early when debug logging is not enabled. In the same
homeassistant run, this saves 0.7% of the runtime.
@ichard26 ichard26 added the type: performance Commands take too long to run label Dec 26, 2024
@ichard26
Copy link
Member Author

ichard26 commented Dec 26, 2024

I noticed while writing a janky demo of installing build dependencies in-process that setuptools was still taking forever to download and install. It turns out setuptools' index page is so huge that requires-python evaluation is pretty slow, taking ~100 ms on my reasonably fast machine. (For reference, the HTTP request took ~500ms.)

Command: python -m cProfile -o profile.pstats -m pip install setuptools --ignore-installed

image

@ichard26 ichard26 changed the title perf: cache requires-python checks & skip debug logging Cache requires-python checks & skip debug logging Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant