Repository navigation
Conversation
Merging this PR will not alter performance
|
| .collect(); | ||
| let nodes: Vec<_> = nodes.into_iter().collect(); |
There was a problem hiding this comment.
[P3] Collect fork nodes directly into the vector
The intermediate FxHashMap is consumed without any lookups, and node_indices immediately hashes the identities again. Filtering to Package nodes with MarkerTree::TRUE already leaves one selected version per interned (name, kind) in a fork, so this map does not provide necessary deduplication. Now that Resolution::nodes is a vector, collect directly into Vec<_> and build node_indices from it, removing a transient allocation and redundant hashing pass for each fork.
3665d8f to
cc8775d
Compare
## Summary We currently clone the full package identity and version for both endpoints of every dependency edge. On large graphs, this duplicates the same information many times, especially across resolver forks. This stores each fork's nodes in a vector and represents dependency edges using indices into that vector. When merging forks, we translate those indices into output graph nodes before deduplicating edges. Package source, version, extras, and dependency groups remain part of the node identity. Port of [uv-dev#2453](astral-sh#2453). ## Benchmarks On a Linux AMD EPYC devbox, we measured fresh, offline `uv lock` runs for synthetic local projects with warm caches. The results are means from 30 runs per revision: | Project | Peak RSS, before → after | Wall time, before → after | | ----------------------------------------------------- | -------------------------: | ------------------------: | | 1,000 packages, up to 1 dependency each | 96.0 → 93.5 MiB (-2.6%) | 1.451 → 1.453 s (+0.1%) | | 1,000 packages, up to 10 dependencies each | 126.1 → 114.0 MiB (-9.6%) | 2.112 → 2.086 s (-1.2%) | | 2,000 packages, up to 20 dependencies each | 315.5 → 276.8 MiB (-12.3%) | 8.683 → 8.519 s (-1.9%) | | 1,000 packages, up to 10 dependencies each, two forks | 147.2 → 117.6 MiB (-20.1%) | 2.264 → 2.206 s (-2.6%) | Jupyter and Trio showed no clear change. The wall-time differences are small: identical-binary controls varied by around 1%. The comparison used release builds of `c8e4086` and `93a96e9`. The latter predates removal of two explicit drops; a separate comparison found no significant difference from removing them. --------- Co-authored-by: zaniebot <[email protected]>
cc8775d to
ace2b86
Compare
Intermediate resolver edges retain complete package identities for their endpoints while the fork already owns the selected nodes. Store indices into each fork's node vector and translate them into output graph positions before deduplicating edges. Borrow package identities during lookup and release each fork's buffers as it is merged. The merge distinguishes package sources, versions, and virtual extra/group nodes, choosing selected artifacts from the first fork that supplies a matching node.
Hyperfine 2.0.0 measurements of 301799d97 → 3665d8fe2 used release builds with Rust 1.99.0 and CPython 3.12.13 on an AMD EPYC-Genoa Linux VM, pinned to four CPUs. The command was
uv lock --no-index --python PYTHON --directory FIXTURE --offline --no-config --color never --cache-dir CACHE, with warm OS page caches and output sent to/dev/null.The root and its dependencies are local virtual projects with static metadata. The root depends on all listed packages; each package depends on up to the indicated number of later packages, forming an acyclic graph with shared targets. Ordinary source paths are 63 characters relative to the root. The forked case adds two versions of another local package, selected by mutually exclusive Linux and non-Linux markers. Hyperfine's
--prepareremovesuv.lockand restores the root project before each invocation; restoration is excluded from time and peak RSS. Every invocation performs fresh universal resolution and writes its lockfile, without a build backend, wheel download, or installation.Values are means, parent → head. Changes are
(head / parent - 1)with 95% confidence intervals; negative values indicate a reduction.Each workload used ten comparison blocks with alternating revision order, one warmup followed by three measured runs per revision in each block (30 measurements per revision). The 95% percentile-bootstrap intervals use 20,000 resamples of paired block means and retain all samples. They estimate within-run uncertainty, not variation across machines, independent builds, or separate benchmark campaigns.
The largest graph uses about 54.9 MiB less peak RSS (13.8%) and takes 2.4% less time. The forked graph uses about 33.1 MiB less peak RSS (18.2%) and takes 4.1% less time. For 1,000 packages with at most one outgoing dependency each, the runtime interval includes zero while peak RSS falls by about 3.9 MiB. These synthetic local-source graphs measure the whole command, including metadata reading, universal resolution, intermediate and final graph construction, and lockfile serialization. They do not isolate endpoint storage or establish the effect on registry-index workloads. RSS is Hyperfine's Linux
wait4peak, not an allocation count or summed simultaneous process-tree memory.