rust/library/alloc/src/collections
Mara Bos c013dc01f1
Rollup merge of #81127 - hanmertens:binary_heap_sift_down_perf, r=dtolnay
Improve sift_down performance in BinaryHeap

Replacing `child < end - 1` with `child <= end.saturating_sub(2)` in `BinaryHeap::sift_down_range` (surprisingly) results in a significant speedup of `BinaryHeap::into_sorted_vec`. The same substitution can be done for `BinaryHeap::sift_down_to_bottom`, which causes a slight but probably statistically insignificant speedup for `BinaryHeap::pop`. It's interesting that benchmarks aside from `bench_into_sorted_vec` are barely affected, even those that do use `sift_down_*` methods internally.

| Benchmark                | Before (ns/iter) | After (ns/iter) | Speedup |
|--------------------------|------------------|-----------------|---------|
| bench_find_smallest_1000<sup>1</sup> | 392,617          | 385,200         |    1.02 |
| bench_from_vec<sup>1</sup>           | 506,016          | 504,444         |    1.00 |
| bench_into_sorted_vec<sup>1</sup>    | 476,869          | 384,458         |    1.24 |
| bench_peek_mut_deref_mut<sup>3</sup> | 518,753          | 519,792         |    1.00 |
| bench_pop<sup>2</sup>                | 446,718          | 444,409         |    1.01 |
| bench_push<sup>3</sup>               | 772,481          | 770,208         |    1.00 |

<sup>1</sup>: internally calls `sift_down_range`
<sup>2</sup>: internally calls `sift_down_to_bottom`
<sup>3</sup>: should not be affected
2021-03-09 09:05:18 +00:00
..
btree Rollup merge of #82764 - m-ou-se:map-try-insert, r=Amanieu 2021-03-05 10:57:22 +01:00
linked_list Remove linked_list_extras methods. 2020-08-01 00:54:22 +08:00
vec_deque Rename Range::ensure_subset_of to slice::range 2021-02-12 22:01:04 -05:00
binary_heap.rs Rollup merge of #81127 - hanmertens:binary_heap_sift_down_perf, r=dtolnay 2021-03-09 09:05:18 +00:00
linked_list.rs Add diagnostic items 2021-03-01 09:04:11 -06:00
mod.rs Rename LayoutErr to LayoutError outside of core 2020-10-08 00:40:10 -04:00