Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Build a Smaller uv

Build a package synchronizer that resolves a graph, concurrently prepares immutable artifacts into an atomic cache, and applies a plan under an exclusive target lock.

1. Resolve a concrete registry

Use an in-memory map from (name, version) to dependencies. Implement backtracking for version constraints and produce a complete Resolution before touching a target directory.

2. Add asynchronous metadata

Serve registry records through a fake latency-injecting provider. Feed requests through a bounded channel, overlap responses with FuturesUnordered, and keep the resolver’s decision state in one task.

3. Deduplicate in-flight keys

Implement register_or_wait around a map of shared completion cells. Request one package from five branches and assert the provider runs once. Propagate the same failure to every waiter and remove or finalize the entry deliberately.

4. Separate resource budgets

Add global semaphores for downloads and builds, plus a fixed install-worker count. Record peak counts in tests. Make a recursive source build use the same build semaphore.

5. Publish an immutable cache entry

Download into a temporary directory, verify a checksum and manifest, then rename into a content-addressed archive. Kill the task before and after rename; readers must see either absence or a complete artifact.

6. Calculate a plan

Compare desired resolution with installed manifests and classify keep, remove, install-from-cache, and prepare. Support dry-run by printing the plan without mutation.

7. Lock and apply

Take an OS file lock for the target, remove stale packages, then link or copy files from cache with atomic per-file replacement. Run two synchronizers against one environment and verify their mutation phases never overlap.

8. Bridge blocking work

Put archive extraction in spawn_blocking; run a fake build backend as a child process with captured output and a timeout. Ensure neither consumes unbounded Tokio workers or child processes.

9. Compare with production

Map the result to uv’s resolver/provider, InFlight, Concurrency, DistributionDatabase, Preparer, Plan, Installer, Cache, atomic fs helpers, and environment locks. The real uv adds Python’s full metadata and tag model, PubGrub diagnostics, registries, Git, build isolation, cross-platform link modes, authentication, and extensive cache invalidation. Preserve the center: concurrent evidence gathering, staged decisions, and narrow mutation.