-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer requirements with upper bounds #13273
base: main
Are you sure you want to change the base?
Prefer requirements with upper bounds #13273
Conversation
2d2ad3c
to
de28f96
Compare
My only concern with this is that it could result in people thinking that upper bounds are good, whereas it's generally acknowledged that they are a bad idea in practice. I can imagine people seeing this change and thinking that it means that if they add upper version caps to their requirements, they will get faster resolution times "magically". While the performance numbers can't lie, I would be much happier if we could give a clear explanation of why and when this improves resolution times, in a way that doesn't make it appear that you'll always be better with an upper cap. In particular, the intuition you suggest makes no sense to me - upper version limits don't change an infinite (or even large) set of possibilities into a finite one, the set of possibilities is always finite. I think this is more a matter of how we present the change than a problem with the actual logic, though. If I understand correctly, the real saving is due to the fact that, because pip always tries the latest version available first, requirements that guarantee that one or more of the newest versions will not work allow us to skip those newer versions sooner, so we should prefer them over requirements that don't. The key is that an upper cap is only useful to us if it actually excludes new versions, and therefore it's an explicit "the project is known not to work with recent versions of this dependency" rather than the pre-emptive "we've only tested with dependency versions up to X" cap that's called out as problematic in the article I linked. I don't know how we get that much nuance1 in a release note, though. Maybe we'd be best simply not explaining in the news item - just saying something like "Improve the heuristics for determining the order for resolving dependencies", and adding a short explanatory note ("because this allows us to skip guaranteed-incompatible later versions sooner" or similar) to the docstring and documentation. Footnotes
|
@pfmoore I would say your whole comment is on point and I agree with your concern. In fact it's exactly because adding upper bound requirements makes resolution hard that it's useful to consider them before other requirements, so I definitely don't want to encourage a proliferation of them. I will rethink the documentation, explaining more of the nuance, and the news items, simplifying it to not go into the nuance. |
It's not really important, but the thought process goes like this: Let's say you have versions are released in a strictly monotonically increasing fashion (not always true but often true), e.g. Another, related way, of thinking about it is that upper bounding make statements about the future of a package, which usually is not known for sure, and is therefore can be problematic, but lower bounding requirements say something about the past which can be known, so tend not to be problematic, and resolving problematic requirements first is usually better. Your intuitive explanation is probably a better one, and I'll update to reflect. |
100%. And thanks for the article link @pfmoore - I have not seen it before, but this is pure gold. |
I've updated docs and news entry based on feedback. I'm limiting this PR to just touching the |
a5bc3d2
to
1e68d9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm far from being knowledgeable on dependency resolution, I did spend some time reading the pip documentation on dependency resolution. This makes a lot more sense. LGTM (but this isn't a formal approval).
Fixes: #12993
Fixes: #12990
This is the last PR related to
get_preference
I am making this release cycle, this one provides significant performance improvements for some pathological resolutions, and I don't have any examples where it makes the resolution worse.There are a number of intuitive ways to think about why this would help find a resolution faster, but the one I most like is operators that do not allow versions after a certain version limit the possible versions to some finite set (ignoring that technically a package could never bump their major/minor version number) where as other operators still allow for unbounded future versions to be selected.
Checking against the scenarios in Pip-Resolution-Scenarios-and-Benchmarks, there are two problematic scenarios that go from failing to succeeding compared to master branch:
Note, for the latter scenario I have the benchmark tool stop at ~15k rounds, where as normally pip won't stop till 200k rounds.