-
Notifications
You must be signed in to change notification settings - Fork 507
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
Caching doesn't seem to save that much time #881
Comments
Hello @hamirmahal |
You're welcome @HarithaVattikuti. |
@hamirmahal I'm not a developer but want to respond to your ticket. DiagnosisThe However, "Collecting" and "Using" aren't actually consuming much time -- it's the installation itself that consumes the vast majority of time. You can verify this by reviewing the raw logs, which contain a timestamp for every output line: Looking at those raw logs, pip spends ~6 seconds (from Best practiceMy recommendation is to disable setup-python's pip caching entirely and focus exclusively on caching an entire virtual environment. steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
id: setup-python
with:
python-version: "3.11"
# Write the exact Python version to a file for cache-busting.
- run: |
echo "${{ steps.setup-python.outputs.python-version }}" > ".installed-python"
# THIS! This is where you'll save all your time!
# Never cache pip dependencies! Cache virtual environments!
- uses: "actions/cache@v4"
id: "restore-cache"
with:
key: "venv-${{ hashFiles('.installed-python', 'requirements.txt') }}"
path: |
.venv/
# If Python 3.11.x upgrades to 3.11.y, or if requirements.txt gets updated,
# the cache lookup above will miss, and the venv needs to be recreated.
- name: "Create a virtual environment"
if: "steps.restore-cache.outputs.cache-hit == false"
run: |
python -m venv .venv
.venv/bin/python -m pip install --upgrade pip setuptools wheel
.venv/bin/python -m pip install -r requirements.txt
- run: .venv/bin/python src/main.py Caching an entire virtual environment is going to save you a ton of time. The only thing you need to watch out for is cache-busting. The example above busts the cache based on the exact Python version (like "3.11.7") and based on your @HarithaVattikuti I think that this ticket can be closed; the report is referring to pip behavior, not setup-python behavior. |
Hello @hamirmahal 👋, |
Description:
Caching seems to only skip the downloading step. It would be nice if it skipped
Collecting
andUsing
altogether, since that could maybe save a lot more time.Action version:
v5
Platform:
Runner type:
Tools version:
Repro steps:
https://github.com/hamirmahal/cache-pip-install/actions/runs/8963287619/job/24613359851#step:4:1
Expected behavior:
Caching saves a lot more time.
Actual behavior:
Caching only saves about 6s or so on an install step that otherwise takes a minute.
The text was updated successfully, but these errors were encountered: