Page MenuHomeFreeBSD

libc: Drop incorrect qsort optimization
ClosedPublic

Authored by des on Aug 14 2025, 11:44 PM.
Tags
None
Referenced Files
F151384393: D51907.id160389.diff
Wed, Apr 8, 1:28 AM
Unknown Object (File)
Sat, Mar 28, 6:20 AM
Unknown Object (File)
Tue, Mar 17, 6:36 AM
Unknown Object (File)
Mon, Mar 16, 10:14 PM
Unknown Object (File)
Mon, Mar 16, 1:09 PM
Unknown Object (File)
Mon, Mar 16, 8:54 AM
Unknown Object (File)
Mon, Mar 16, 2:42 AM
Unknown Object (File)
Mar 2 2026, 2:46 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