[libcxx-commits] [libcxx] [libc++] Optimize make_heap() and sift_down() (PR #121480)

Yang Kun via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 4 04:03:12 PST 2025


omikrun wrote:

Oh, according to the `libcxx/algorithms/alg.sorting/alg.heap.operations/make.heap/complexity.pass.cpp` broken due to my changes, I think my previous codes are bad (but it more cache-friendly I think, that's the reason why it is faster). However the complexity is worse. Finally, I rewrite the whole codes in this PR just to simplify assembly codes.

`make_heap()` generates [better assembly codes](https://godbolt.org/z/febso9K5b) on GCC now (yes, clang++ properly optimized it but GCC not).

Additionally, `__sift_down()` have a better performance in random access iterator (e.g.`std::deque<int>::iterator).

https://github.com/llvm/llvm-project/pull/121480


More information about the libcxx-commits mailing list