Page MenuHomeFreeBSD

libc: Drop incorrect qsort optimization
ClosedPublic

Authored by des on Aug 14 2025, 11:44 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 10, 3:39 AM
Unknown Object (File)
Thu, Oct 9, 7:15 PM
Unknown Object (File)
Thu, Oct 9, 7:15 PM
Unknown Object (File)
Thu, Oct 9, 7:15 PM
Unknown Object (File)
Thu, Oct 9, 4:47 PM
Unknown Object (File)
Wed, Sep 17, 5:26 AM
Unknown Object (File)
Tue, Sep 16, 4:34 AM
Unknown Object (File)
Sep 15 2025, 3:23 PM
Subscribers

Details

Summary

As pointed out in the PR and the article linked below, the switch to
insertion sort in the BSD qsort code is based on a misunderstanding of
Knuth's TAOCP and is actually a pessimization. As demonstrated by the
added test, it is trivially easy to construct pathological input which
results in quadratic runtime. Without that misguided optimization, the
same input runs in nearly linearithmic time.

https://www.raygard.net/2022/02/26/Re-engineering-a-qsort-part-3

PR: 287089

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable