Sorts inputs of at most 20 elements with a guarded insertion sort; otherwise scans for pre-sorted runs with a √n acceptance threshold (capped at 64), reverses strictly descending runs, and schedules the merges with a Powersort merge tree.
Adjacent unsorted runs are merged only logically — concatenated while they still fit the scratch buffer — so fully random input degenerates into one large out-of-place stable quicksort while structured input takes the merge path. A pivot equal to the left-ancestor pivot triggers an equal-partition pass, giving O(n log k) behavior for k distinct values. The algorithm behind Rust's stable sort since 1.81.