Github Improve sift_down performance in BinaryHeap by hanmertens · Pull Request...
source link: https://github.com/rust-lang/rust/pull/81127
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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.
1: internally calls sift_down_range
2: internally calls sift_down_to_bottom
3: should not be affected
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK