Repository navigation
Conversation
9ed127b to
f820e40
Compare
Merging this PR will improve performance by 16.58%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ |
Simulation | discover_workspace_from_all_members_with_excludes |
165.6 ms | 139.9 ms | +18.35% |
| ⚡ |
Simulation | discover_workspace_from_all_members |
151.5 ms | 132 ms | +14.83% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing zb/shared-lock-traversal (10cf0b2) with main (64e2ac8)
Footnotes
-
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. ↩
0510734 to
2d4d76a
Compare
2d4d76a to
da77572
Compare
da77572 to
b3c3778
Compare
547e378 to
9aa6104
Compare
5c4d2ea to
85d4b41
Compare
| let external_reachability = site_packages.reachable_packages( | ||
| site_packages | ||
| .iter() | ||
| .filter(|distribution| !managed.contains(distribution.name())) | ||
| .map(|distribution| (distribution.name(), &[] as &[ExtraName])), |
There was a problem hiding this comment.
[P2] Follow replacement dependencies during external retention
The managed filter excludes traversal roots, but reachable_packages can still follow an external package into a managed package's old installed metadata. For example, extend the staged remaining 1→2 upgrade in remove_subset_ignores_replaced_package_dependencies with an unmanaged package requiring remaining. The walk follows remaining==1.0.0 to candidate and retains it, although this operation installs remaining==2.0.0, which no longer needs it. Pruning therefore leaves an orphan. Distinguish replaced distributions during retention traversal and use their replacement dependencies; add coverage for an external path through an upgraded package.
| modifications: Modifications, | ||
| prune: Option<PrunePolicy>, |
There was a problem hiding this comment.
[P3] Represent the removal modes with one input
These inputs represent three mutually exclusive modes, but Some(prune) silently overrides modifications. Consequently, remove passes Exact while retaining unrelated packages, and the API also accepts Sufficient with a policy that deletes extraneous packages. Callers must understand this precedence instead of relying on the documented meaning of Modifications. Use an installation-layer enum for sufficient, exact, and pruning modes, converting the existing configuration value at the boundary.
| /// Transitive dependencies of the requested packages will be removed from the environment | ||
| /// unless they are required by another dependency in the project. |
There was a problem hiding this comment.
[P3] Document retention by other installed packages
The exception omits unmanaged installed packages, which also prevent pruning. For example, remove_subset_prunes_only_unshared_branches retains candidate because manually installed external requires it, despite no remaining project declaration requiring it. Mention both remaining project declarations and other installed packages so the help describes the implemented cleanup policy.
| let Ok(metadata) = distribution.read_metadata() else { | ||
| incomplete.insert(package.clone()); | ||
| continue; | ||
| }; |
There was a problem hiding this comment.
[P3] Preserve the cause of installed metadata failures
When installed metadata is missing, unreadable, or malformed, this discards the InstalledDistError. PrunePolicy subsequently logs only package names and proceeds with pruning, so verbose output cannot explain why dependency information was ignored. Log the error with the distribution path here, or retain it in InstalledReachability, while keeping the intended best-effort behavior.
| ├── remaining | ||
| │ ├── remaining-1.0.0 | ||
| │ │ └── requires candidate | ||
| │ │ └── satisfied by candidate-1.0.0 | ||
| │ └── remaining-2.0.0 |
There was a problem hiding this comment.
[P3] Refresh the documented replacement dependency graph
The linked fixture diagram omits remaining[foo] for both versions and the remaining-external and remaining-extra-external packages present in the TOML. These edges explain the different retention expectations in the replacement tests, so their omission makes those tests harder to assess. Update the diagram from the current fixture and correct its generation header: cargo dev render-scenario is not an available subcommand in this checkout.
| assert_eq!(context.read("uv.lock"), "invalid lock"); | ||
| assert!(!context.read("pyproject.toml").contains("candidate")); |
There was a problem hiding this comment.
[P3] Snapshot the frozen removal result
Unlike remove_requirement and neighboring edit tests, this test checks only command success and substring absence. An empty or truncated pyproject.toml would satisfy the assertion, and unexpected command output would go unnoticed. Use uv_snapshot! for the removal command and assert_snapshot! for the edited TOML to verify the expected edit and intact project fields. Keep the exact equality check for the deliberately invalid lockfile.
5f44824 to
1b5c6f1
Compare
| if matches!( | ||
| distribution.kind, | ||
| InstalledDistKind::EggInfoFile(_) | ||
| | InstalledDistKind::EggInfoDirectory(_) | ||
| | InstalledDistKind::LegacyEditable(_) | ||
| ) { |
There was a problem hiding this comment.
[P3] Classify installed metadata formats exhaustively
This check encodes which installed formats provide complete dependency metadata for pruning. matches! implicitly sends every future InstalledDistKind through the supported path, so adding a format does not require revisiting that assumption. Use an exhaustive match with explicit Registry | Url and legacy-format arms so new variants require a deliberate completeness decision.
1b5c6f1 to
10cf0b2
Compare
10cf0b2 to
72bb8d5
Compare
| let managed = resolution | ||
| .distributions() | ||
| .map(Name::name) | ||
| .chain(candidates.difference(&retained)) | ||
| .collect::<BTreeSet<_>>(); |
There was a problem hiding this comment.
[P2] Include planner-preserved packages in retention roots
This excludes every removal candidate from external roots, even when Planner::build exempts it from plan.extraneous. In a seeded Python 3.11 environment where wheel depends on packaging, removing wheel can therefore retain wheel through the seed-package exemption while pruning packaging. Pass the planned extraneous distributions into this calculation and exclude only candidates actually eligible for removal, so packages preserved by the planner also protect their installed dependencies.
72bb8d5 to
ae72caa
Compare
| site_packages | ||
| .iter() | ||
| .filter(|distribution| !managed.contains(distribution.name())) | ||
| .map(|distribution| (distribution.name(), &[] as &[ExtraName])), |
There was a problem hiding this comment.
[P2] Carry declared extras into the installed retention walk
Seeding every retained installed package with empty extras can prune dependencies of an unselected group. For example, sync a non-default group containing a[foo]==1, where foo requires c, then update it to a[foo]==2 with --no-sync, where foo no longer requires c. Removing another dependency that requires c leaves a==1 installed, but the new lock does not retain c and this installed walk never visits a[foo], so c is uninstalled. The extra remains explicitly declared; it is not merely historical pip install state. Carry declared extra activations alongside retained names and use them when traversing packages left installed, extending the existing staged unselected-group regression coverage.
End-to-end sketch of shared dependency traversal, including the removal pruning from astral-sh#20192. The complete sketch comparison shows the four commits together. Lock consumers share package/extra identity and dependency expansion through
LockWalkerandMarkerReachabilityWalker. The latter uses the same marker-accumulation machinery as resolver graph propagation, whileOnceQueuealso serves installed-metadata traversal, recursive extra expansion, and tree filtering. Workspace metadata, workspace-member selection, and root-requirement matching are included in the sketch.The commits separate the traversal foundation, adoption by the remaining consumers, and removal integration. Removal keeps its conservative environment and conflict-selection policy above the shared walker. Metadata validation, path-sensitive tree rendering, and export's conflict inference retain their richer state; their different revisit rules are documented alongside the shared walkers. This is an alternative design sketch and does not change the existing upstream stack.