perf: avoid repeated dependency scans in pip show #14103
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 374 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.355
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #14103"
general
weight: 0.35
2ykwang
Fixes #14102.
pip showcurrently computesRequired-byseparately for each queried package.For multiple queried packages, this repeatedly scans all installed distributions
and parses dependency metadata.
This PR avoids that repeated work. For a single queried package, it keeps a
direct lookup path and short-circuits dependency scans when possible. For
multiple queried packages, it builds the reverse dependency mapping once while
walking installed distributions, then reuses it for each queried package.
Benchmark
---------
I used
python -m timeitwith a mocked installed environment containing 2,000distributions and 1,000 dependents, varying the number of queried packages.
To reproduce, run this once on
mainand once on this PR branch:My latest results:
| queried packages | main | PR |
| --- | ---: | ---: |
| 1 | 662 usec/loop | 313 usec/loop |
| 5 | 2.85 msec/loop | 485 usec/loop |
| 20 | 11.1 msec/loop | 509 usec/loop |
| 50 | 27.5 msec/loop | 578 usec/loop |
This keeps the common single-package case faster than
main, while preservingthe expected scaling improvement for multiple queried packages.