Uh oh!
There was an error while loading. Please reload this page.
Improve rebuilding behaviour of BinaryHeap::retain. - #78681
Conversation
rust-highfive
commented
Nov 2, 2020
r? @kennytm (rust_highfive has picked a reviewer for you, use r? to override) |
kennytm
commented
Nov 7, 2020
r? @Amanieu |
Dylan-DPC-zz
commented
Nov 24, 2020
r? @KodrAus |
KodrAus
commented
Jan 14, 2021
This looks good to me! But it would be nice to see a microbenchmark or two to get an idea of what kind of a difference it makes. |
bors
commented
Jan 16, 2021
☔ The latest upstream changes (presumably #77435) made this pull request unmergeable. Please resolve the merge conflicts. |
JohnCSimon
commented
Feb 1, 2021
returning to author to address the merge conflict |
Dylan-DPC-zz
commented
Apr 1, 2021
r? @Amanieu |
Amanieu
commented
Apr 1, 2021
r=me once the merge conflict is fixed. |
Amanieu
commented
Apr 22, 2021
ping @m-ou-se Can you resolve the merge conflict so that we can merge this? |
It now doesn't fully rebuild the heap, but only the parts that are necessary.
3ffb493 to
f5d72abComparem-ou-se
commented
Apr 22, 2021
Thanks for the reminder! @bors r=Amanieu |
bors
commented
Apr 22, 2021
📌 Commit f5d72ab has been approved by |
Improve rebuilding behaviour of BinaryHeap::retain. This changes `BinaryHeap::retain` such that it doesn't always fully rebuild the heap, but only rebuilds the parts for which that's necessary. This makes use of the fact that retain gives out `&T`s and not `&mut T`s. Retaining every element or removing only elements at the end results in no rebuilding at all. Retaining most elements results in only reordering the elements that got moved (those after the first removed element), using the same logic as was already used for `append`. cc `@KodrAus` `@sfackler` - We briefly discussed this possibility in the meeting last week while we talked about stabilization of this function (rust-lang#71503).
bors
commented
Apr 23, 2021
bors
commented
Apr 23, 2021
☀️ Test successful - checks-actions |
This commit ports the change in the rebuild heuristic used by `BinaryHeap::append()` that was added in rust-lang/rust#77435: "Change BinaryHeap::append rebuild heuristic". See also the discussion in rust-lang/rust#77433: "Suboptimal performance of BinaryHeap::append" for more information on how the new heuristic was chosen. It also ports the new private method `.rebuild_tail()` now used by `std::collections::BinaryHeap::append()` from rust-lang/rust#78681: "Improve rebuilding behaviour of BinaryHeap::retain". Note that Rust 1.60.0 adds the clippy lint `manual_bits` which warns against code used here. We suppress the lint instead of following the upstream patch which now uses `usize::BITS`, since this was stabilized in Rust 1.53.0 and this crate's MSRV is currently 1.36.0.
This changes
BinaryHeap::retainsuch that it doesn't always fully rebuild the heap, but only rebuilds the parts for which that's necessary.This makes use of the fact that retain gives out
&Ts and not&mut Ts.Retaining every element or removing only elements at the end results in no rebuilding at all. Retaining most elements results in only reordering the elements that got moved (those after the first removed element), using the same logic as was already used for
append.cc @KodrAus@sfackler - We briefly discussed this possibility in the meeting last week while we talked about stabilization of this function (#71503).