rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.37k stars 12.59k forks source link

[ER] Two ideas for stdlib sorting #84173

Open leonardo-m opened 3 years ago

leonardo-m commented 3 years ago

1) The first idea is to integrate in the stdlib sort a radix sort. It's mean to be used only in basic cases where it can generate or use standard Radixable trait for an algorithm like this one. The current stdlib algorithm is to be used as fall-back. The radix sorting could be quite useful because it covers many basic sorting cases: https://crates.io/crates/voracious_radix_sort

2) Code like this generates about 740 asm instructions with about seven slice bound tests:

pub fn foo(p: &mut [u32]) {
    p.sort();
}

While this generates about 1300 lines of asm with about 16 bound tests/bound asserts:

pub fn foo(p: &mut [u32]) {
    p.sort_unstable();
}

Perhaps rearranging things a little inside the sorting there are ways to reduce that number of bound tests a bit (without introducing new unsafe code).

clubby789 commented 1 year ago

@rustbot label +T-libs