See 5205b32de3fb ("libc: Drop incorrect qsort optimization") for
additional details.
PR: 287089
MFC after: 1 week
Differential D51920
libkern: qsort: Sync with libc sources jlduran on Aug 15 2025, 3:01 PM. Authored by Tags None Referenced Files
Details See 5205b32de3fb ("libc: Drop incorrect qsort optimization") for PR: 287089
Diff Detail
Event TimelineComment Actions Address suggestions:
Comment Actions Have you looked into how feasible it would be to sync them up and just have libc reach into libkern for the bulk of the implementation? Comment Actions I had the same thought, but I would prefer if we landed this first so I can MFC it without the build changes. Comment Actions I'm going to land D51919 now so I can MFC the smallest possible change, then you can turn this review into a patch that moves libc qsort.c into libkern and has libc pull it from there. Comment Actions OK, will look into that. OK, let's go with this plan. It also buys me some time to test the benchmarks described in the article, for comparison. Comment Actions I'm curious to hear you're reasoning there... in general, these things frequently get out of sync and I can't imagine off-hand why we wouldn't want to reduce our maintenance burden if the implementations are (or should be) largely the same. Comment Actions Just to have kernel/userland implementations. Note that I'm not opposed to the idea, in fact, I will look into it. Comment Actions It will take a while. [1]: https://github.com/jlduran/qsort_dev/actions/runs/17001051638/job/48202771322 Comment Actions I already benchmarked NetBSD's code, we're about twice as fast as them. Apple's code is ours (including the insertion sort bug) with an added recursion limit. Comment Actions I'm testing with the current version from https://github.com/apple-oss-distributions/Libc/blob/main/stdlib/FreeBSD/qsort.c although it has swap_cnt it doesn't go quadratic (e.g., testing the minimal example from bug #287089 on a mac results in qsort: 886371 compares, 0.003354 seconds). As you well point out, we are their upstream, so the diff is minimal compared to the others. |