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

Prefetch all packages in uv lock --upgrade #7427

Closed
wants to merge 1 commit into from

Conversation

konstin
Copy link
Member

@konstin konstin commented Sep 16, 2024

When we upgrade the lockfile, we know that we have to fetch all packages. We can speed this up by queueing all packages from the lockfile eagerly.

The disadvantage is that we block the queue until all of them are done. I tried adding a priority and a prefetch lock, but that regressed performance.

I get the impression we could speed up uv esp. for the cache-evicted case by adding priorities to the requests.

Benchmark

Small data science project:

[project]
name = "data-science"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
  "beautifulsoup4>=4.12.3,<5",
  "httpx>=0.27.0,<0.28",
  "matplotlib>=3.9.1,<4",
  "numpy>=2.0.1,<3",
  "pandas>=2.2.2,<3",
  "pydantic>=2.8.2",
  "scikit-learn>=1.5.1,<2",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
  "ruff<=0.6.2,<0.7",
  "jupyter>=1.0.0,<2.0.0",
]
$ hyperfine --prepare "sleep 5" --runs 20 "./uv lock --upgrade" "uv lock --upgrade"
Benchmark 1: ./uv lock --upgrade
  Time (mean ± σ):     239.3 ms ±  68.3 ms    [User: 76.0 ms, System: 127.9 ms]
  Range (min … max):   193.0 ms … 493.5 ms    20 runs

Benchmark 2: uv lock --upgrade
  Time (mean ± σ):     320.0 ms ±  31.1 ms    [User: 66.5 ms, System: 90.9 ms]
  Range (min … max):   291.5 ms … 382.0 ms    20 runs

Summary
  ./uv lock --upgrade ran
    1.34 ± 0.40 times faster than uv lock --upgrade

transformers:

$ hyperfine --prepare "sleep 10" --runs 100 "~/projects/uv/target/release/uv lock --upgrade" "uv lock --upgrade"
Benchmark 1: ~/projects/uv/target/release/uv lock --upgrade
  Time (mean ± σ):     572.3 ms ± 128.1 ms    [User: 322.8 ms, System: 264.6 ms]
  Range (min … max):   439.7 ms … 1007.1 ms    100 runs
 
Benchmark 2: uv lock --upgrade
  Time (mean ± σ):     729.7 ms ± 124.4 ms    [User: 324.7 ms, System: 239.4 ms]
  Range (min … max):   570.7 ms … 1131.7 ms    100 runs
 
Summary
  ~/projects/uv/target/release/uv lock --upgrade ran
    1.27 ± 0.36 times faster than uv lock --upgrade

Fixes #1206

@konstin konstin added enhancement New feature or improvement to existing functionality performance Potential performance improvement labels Sep 16, 2024
@charliermarsh
Copy link
Member

@konstin -- Is this intended to be reviewed, or blocked on priority queueing?

@konstin konstin marked this pull request as draft September 24, 2024 09:09
@konstin
Copy link
Member Author

konstin commented Sep 24, 2024

I'll try if i can turn this into a better abstraction

@konstin konstin force-pushed the konsti/prefetch-packages-in-upgrade branch from 61cdb2f to 5886f64 Compare January 10, 2025 13:53
@konstin
Copy link
Member Author

konstin commented Jan 10, 2025

I can't get a measurable effect anymore.

@konstin konstin closed this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality performance Potential performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefetch all dependencies when resolving with a lockfile
2 participants