Skip to content

Prototype uv download with packed archive caching - #875

Draft
zaniebot wants to merge 24 commits into
mainfrom
zb/uv-download-packed
Draft

zaniebot wants to merge 24 commits into
mainfrom
zb/uv-download-packed

Conversation

@zaniebot

@zaniebot zaniebot commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Add a preview uv download command that reads the existing uv.lock and stores every recorded wheel and source archive, across platforms, in a packed cache without resolving, unpacking, or building packages. Distribution and wheel-metadata readers can consume these archives during later operations, including with --offline.

The intent is to separate fetching distributions from preparing them for installation. Today, downloading generally means unpacking into uv's installation-oriented cache, coupling network access to preparation. A separate command lets users fetch everything while online, then install or build later without needing the network or executing build backends during the download phase.

Command semantics

uv download treats the existing uv.lock as an artifact manifest:

  • Fetch every recorded wheel and source archive, including other platforms and compressed-wheel variants.
  • Preserve the original archive bytes.
  • Don't resolve, update the lockfile, create an environment, or build anything.

Normal uv sync wouldn't start downloading every platform's wheels or retaining packed copies.

Cache design

The prototype adds a separate packed-v1 bucket using the same source and normalized-package shards as the wheel cache. Archive payloads and their pointers are flat siblings within each package shard:

packed-v1/
├── pypi/<package>/
│   ├── <sha256>
│   ├── <wheel-key>.http
│   └── <version>.<sdist-extension>.http
├── index/<index-digest>/<package>/
│   ├── <sha256>
│   └── <artifact-key>.http
├── url/<url-digest>/<package>/
│   ├── <sha256>
│   └── <artifact-key>.http
└── path/<path-digest>/<package>/
    ├── <sha256>
    └── <artifact-key>.rev

The SHA-256-named file contains the original archive bytes. .http entries retain the HTTP cache policy and point to that payload; local files use timestamped .rev pointers. Downloads go through a temporary file, verify any lockfile hash and size, then publish the pointer last. Later reads recheck the stored bytes; --refresh and package-scoped cache cleanup are supported.

When installation needs an archive, it can use the packed copy instead of fetching it. Preparation still populates the usual unpacked or built-wheel cache, so unpacking is deferred rather than eliminated and both representations can exist.

Where the prototype takes a shortcut

The current read-side integration adapts a packed file into an HTTP response. That lets the existing wheel and sdist extraction callbacks consume it with relatively little change while retaining the saved cache policy for remote artifacts. Wheel metadata also has a direct packed-file reader, avoiding network metadata requests.

The adapter still performs streamed unpacking, just from disk. An upstream implementation could instead use an explicit file-backed artifact input shared by the wheel and sdist preparation paths, keeping packed-cache policy separate from HTTP caching and allowing consumers to use seekable local archive readers directly.

Boundaries

This makes installation from an unchanged lockfile possible offline; it isn't a complete offline repository mirror. It doesn't fetch Git checkouts, replace local source trees, or discover build dependencies missing from the lockfile.

The principal costs are downloading potentially many platform variants, retaining a second representation after unpacking, and the prototype's full-file integrity pass before each packed read.

Follow-ups

@astral-automations-bot astral-automations-bot Bot added enhancement New feature or request preview Experimental behavior labels Aug 28, 2026
@zaniebot zaniebot added priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. size:5 Project-sized: too much semantic scope for a normal review; needs decomposition or design review. risk:3 Credible risk of meaningful incorrect behavior or regression; bounded or recoverable. labels Sep 9, 2026
@codspeed

codspeed Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 10.06%

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

❌ 1 regressed benchmark
✅ 53 untouched benchmarks
⏩ 35 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ WallTime resolve_warm_jupyter_universal 11.6 ms 12.9 ms -10.06%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zb/uv-download-packed (a4c397e) with main (4efeeaf)

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment on lines +245 to +250
write_atomic(
self.entry.path(),
rmp_serde::to_vec_named(&LocalPointer { timestamp, archive })?,
)
.await?;
Ok(true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Connect local packed archives to preparation

Local wheels and sdists are copied here and reported as downloaded, but LocalPointer is read only by download_local. Installation and metadata loading still use load_wheel, wheel_metadata_local, and archive_revision, which require the original file. Removing or unmounting that file after uv download therefore makes offline installation fail despite the packed copy. Add a local packed-cache reader to those consumers and cover downloading followed by removal of the original archive.

Comment thread crates/uv/tests/project/download.rs Outdated
Comment on lines +198 to +202
let zstd = fs_err::read(
context
.workspace_root
.join("test/links/basic_package-0.1.0-py3-none-any.whl.tar.zst"),
)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Update the offline test for the current wheel format

The referenced .whl.tar.zst fixture does not exist in this checkout, so this test returns an I/O error before exercising download. Restoring the file alone would not fix it: WheelWire deliberately ignores deprecated zstd metadata, so the manifest produces three artifacts, not the asserted four. Remove the compressed-wheel fixture, mock, and cache assertions and update the counts while retaining the incompatible-wheel and sdist coverage.

Comment thread crates/uv-lock/src/lock/mod.rs Outdated
Comment on lines +6643 to +6646
pub struct LockedArtifact {
pub index: Option<IndexUrl>,
pub cache_key: String,
pub url: DisplaySafeUrl,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep artifact identity structured across the cache boundary

LockedArtifact discards the wheel filename or source version/format in favor of a packed-cache key. Producers and consumers must then independently pair the index with the correct key recipe, including remembering when a source key needs a version. The shared formatting helpers do not enforce that relationship. Return a structured wheel/source artifact kind and derive its key in PackedArchiveEntry constructors, keeping cache identity rules owned by the cache implementation.

Comment thread crates/uv/tests/project/download.rs Outdated
Comment on lines +1221 to +1222
uv_snapshot!(context.filters(), context.sync()
.args(["--frozen", "--offline", "--reinstall", "--no-build", "--no-binary-package", "basic-package"]), @"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Verify that CI pruning retains the built wheel

--no-binary-package basic-package overrides the global --no-build: BuildOptions::no_build_package returns false for this package. Consequently, this invocation can rebuild from the retained sdist if pruning deletes the built wheel; the fixture requires no build dependencies, so offline mode does not prevent that either. The snapshot therefore does not establish the built-wheel retention claimed by this test. Record the built wheel's path before pruning and assert that it survives, and remove the ineffective --no-build flag.

@zaniebot
zaniebot deployed to automations October 10, 2026 01:15 — with GitHub Actions Active
zanieb and others added 24 commits October 21, 2026 12:03
* Align packed distributions with cache conventions

* Fix cache layout CI failures

* Document packed cache layout

---------

Co-authored-by: Zanie Blue <[email protected]>
Comment on lines +836 to +840
let payload = client
.get_serde_with_retry(req, cache_entry, cache_control.clone(), &response_callback)
.await?;
if is_valid(&payload) {
return Ok(payload);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Invalidate packed pointers after preparation refreshes

A successful origin fetch here updates the prepared cache without invalidating the older packed pointer; revision-checked invalidation currently runs only in the metadata paths. For example, after downloading a mutable wheel URL, a newer lockfile can change its hash and uv sync --frozen --refresh successfully prepare the replacement. A subsequent unrefreshed metadata lookup still prefers the old packed wheel while its policy remains fresh, resolving the old dependencies. Apply the existing revision-checked invalidation to successful origin refreshes during preparation, distinguishing those from cache hits and packed responses. Extend the preparation-refresh test with changed wheel metadata and a subsequent unrefreshed lookup.

This branch was successfully deployed

1 active deployment
automations — db9fd741 Deployed Oct 21, 2026 by astral-automations-bot[bot] via review-code-quality / report #11242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build:skip-release Disable building release binaries for a pull request enhancement New feature or request preview Experimental behavior priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. risk:3 Credible risk of meaningful incorrect behavior or regression; bounded or recoverable. size:5 Project-sized: too much semantic scope for a normal review; needs decomposition or design review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants