perf: avoid repeated dependency scans in pip show - #14103
Conversation
|
If I understand correctly this PR regresses the perf for the case of single package which is unfortunate since that is supposedly a very common use case (certainly more common than querying >5 packages). |
|
@danielhollas good point, made some changes |
1917522 to
30874fb
Compare
|
It feels unnecessary to me the single-name case needs a special case. |
yeah, it does add a bit of complexity, though I was trying to regain the perf loss for the single package path that was mentioned earlier, I regained it and then some. |
2ykwang
left a comment
There was a problem hiding this comment.
the mock reuses a small set of dep names, which is quite cache-friendly. real installs tend to have mostly unique ones. would it be possible to also benchmark against a real installed env? curious whether the speedup holds up there.
|
@2ykwang locally I did benchmark using my venv and system venvs, the speedup wasn't as big as in the body numbers, but still close enough. |
|
Tagging onto @uranusjr's comment, I don't believe it's worth the significant additional complexity for speeding up multi-package pip show invocations. They seem quite rare in practice and this is hardly a performance bottleneck. Even 5 packages at all once is an extreme scenario IMO. |
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:
This keeps the common single-package case faster than
main, while preservingthe expected scaling improvement for multiple queried packages.