-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Use Hashbrown's raw entry API to reduce hashes and clone in priority #10881
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
Conversation
6426cf6
to
4c8c114
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.
I don't find this hard to read
if !self.virtual_package_tiebreaker.contains_key(package) { | ||
self.virtual_package_tiebreaker.insert( | ||
package.clone(), | ||
PubGrubTiebreaker::from( | ||
u32::try_from(self.virtual_package_tiebreaker.len()) | ||
.expect("Less than 2**32 packages"), | ||
), | ||
); | ||
// Pre-compute the key and value. | ||
let hash = self.virtual_package_tiebreaker.hasher().hash_one(package); | ||
let next = self.virtual_package_tiebreaker.len(); | ||
|
||
// Insert into the tiebreaker map, if it doesn't exist. | ||
match self | ||
.virtual_package_tiebreaker | ||
.raw_entry_mut() | ||
.from_key_hashed_nocheck(hash, package) | ||
{ | ||
RawEntryMut::Vacant(entry) => { | ||
entry.insert_hashed_nocheck( | ||
hash, | ||
package.clone(), | ||
PubGrubTiebreaker::from(u32::try_from(next).expect("Less than 2**32 packages")), | ||
); | ||
} | ||
RawEntryMut::Occupied(_) => { | ||
// Nothing to do. | ||
} |
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.
What about using the EntryRef
API?
let len = self.virtual_package_tiebreaker.len();
self.virtual_package_tiebreaker
.entry_ref(package)
.or_insert_with(|| {
PubGrubTiebreaker::from(u32::try_from(len).expect("Less than 2**32 packages"))
});
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.
That doesn’t work unless PubGrubPackage implements From<&PubGrubPackage> for PubGrubPackage.
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.
A bit annoying that they use From
instead of ToOwned
, but treating it as clone works
The relationships I use between the key
K
and borrowed keyQ
isK: Borrow<Q> + From<&Q>
. The reason for not usingQ: ToOwned<K>
is to support key types likeRc<str>
(which is used in a couple of the doctests), which would not be possible withto_owned()
.
(from rust-lang/hashbrown#301)
impl From<&PubGrubPackage> for PubGrubPackage {
fn from(package: &PubGrubPackage) -> Self {
package.clone()
}
}
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.
Ok, we can do that instead.
4c8c114
to
8c4a531
Compare
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.5.22` -> `0.5.24` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>astral-sh/uv (astral-sh/uv)</summary> ### [`v0.5.24`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0524) [Compare Source](astral-sh/uv@0.5.23...0.5.24) ##### Enhancements - Improve determinism of resolution by always setting package priorities ([#​10853](astral-sh/uv#10853)) - Upgrade to `cargo-dist` 0.28.0; improves several installer behaviors ([#​10884](astral-sh/uv#10884)) ##### Performance - Remove dependencies clone in resolver ([#​10880](astral-sh/uv#10880)) - Use Hashbrown's raw entry API to reduce hashes and clone in resolver priority determination ([#​10881](astral-sh/uv#10881)) ##### Bug fixes - Allow fallback to Python download on non-critical discovery errors ([#​10908](astral-sh/uv#10908)) ##### Preview features - Register managed Python version with the Windows Registry (PEP 514) ([#​10634](astral-sh/uv#10634)) ##### Documentation - Improve documentation for some environment variables ([#​10887](astral-sh/uv#10887)) - Add git subdirectory example ([#​10894](astral-sh/uv#10894)) ### [`v0.5.23`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0523) [Compare Source](astral-sh/uv@0.5.22...0.5.23) ##### Enhancements - Add `--refresh` to `uv venv` ([#​10834](astral-sh/uv#10834)) - Add `--no-default-groups` command-line flag ([#​10618](astral-sh/uv#10618)) ##### Bug fixes - Sort extras and groups when comparing lockfile requirements ([#​10856](astral-sh/uv#10856)) - Include `commit_id` and `requested_revision` in `direct_url.json` ([#​10862](astral-sh/uv#10862)) - Invalidate lockfile when static versions change ([#​10858](astral-sh/uv#10858)) - Make GitHub fast path errors non-fatal ([#​10859](astral-sh/uv#10859)) - Remove warnings for `--frozen` and `--locked` in `uv run --script` ([#​10840](astral-sh/uv#10840)) - Resolve `find-links` paths relative to the configuration file ([#​10827](astral-sh/uv#10827)) - Respect visitation order for proxy packages ([#​10833](astral-sh/uv#10833)) - Treat version mismatch errors as non-fatal in fast paths ([#​10860](astral-sh/uv#10860)) - Mark `--locked` and `--upgrade` are conflicting ([#​10836](astral-sh/uv#10836)) - Relax error checking around unconditional enabling of conflicting extras ([#​10875](astral-sh/uv#10875)) ##### Documentation - Reduce ambiguity in conflicting extras example ([#​10877](astral-sh/uv#10877)) - Update pre-commit documentation ([#​10756](astral-sh/uv#10756)) ##### Error messages - Error when workspace contains conflicting Python requirements ([#​10841](astral-sh/uv#10841)) - Improve uvx error message when uv is missing ([#​9745](astral-sh/uv#9745)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMjIuMCIsInVwZGF0ZWRJblZlciI6IjM5LjEyNC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Summary
I'm open to not merging this -- I was kind of just interested in what the API looked like. But the idea is: we can avoid hashing values twice and unnecessarily cloning within the priority map by using the raw entry API.