Page MenuHomeFreeBSD

Add a compile time warning for qsort() about issues regarding execution time.
Needs RevisionPublic

Authored by hselasky on Apr 20 2023, 5:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 17 2024, 11:02 AM
Unknown Object (File)
Oct 7 2024, 3:23 AM
Unknown Object (File)
Oct 6 2024, 10:41 AM
Unknown Object (File)
Oct 3 2024, 2:04 AM
Unknown Object (File)
Oct 2 2024, 11:20 PM
Unknown Object (File)
Oct 2 2024, 11:15 PM
Unknown Object (File)
Oct 2 2024, 7:11 PM
Unknown Object (File)
Sep 26 2024, 3:58 PM
Subscribers

Details

Summary

To make developers think carefully through the use of this function
under FreeBSD, until further.

MFC after: 1 week
Sponsored by: NVIDIA Networking

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

jrtc27 requested changes to this revision.Apr 20 2023, 5:39 PM

No. This is a widely-used ISO C function. If it has poor performance, fix that.

This revision now requires changes to proceed.Apr 20 2023, 5:39 PM
brooks requested changes to this revision.Apr 20 2023, 5:46 PM

Absolutely not.

No. This is a widely-used ISO C function. If it has poor performance, fix that.

The ISO C standard does not mandate any kind of performance nor implementation. So why not state that?

It doesn't look apparent to me FreeBSD developers know about this, when you grep through the FreeBSD sources:

freebsd-src % find . -name "*.[ch]" | xargs grep qsort | wc -l

600

freebsd-src % find . -name "*.[ch]" | xargs grep mergesort | wc -l

46

freebsd-src % find . -name "*.[ch]" | xargs grep heapsort | wc -l

34

freebsd-src % find . -name "*.[ch]" | xargs grep radixsort | wc -l

12

freebsd-src %

As long as qsort() is implemented like it is in libc it should be warned about or stated somewhere obvious.

--HPS

It's legal to implement malloc as sleep(UINT_MAX); /* actual malloc code */ per ISO C's specification, or any other standard function for that matter. Everyone understands that implementations should be efficient where reasonable. You're just being obtuse here at this point. I have no interest in furthering this inane discussion.

I have to admit that I get bitten by the function name. I almost always treat qsort() as quicksort but it is actually a generic interface for sorting.
So it should be treated / named as sort() .

A second thought about this, I think for STD C or POSIX, use an implementation as standard is not scalable, as there're so many sorting algorithms.

From qsort(3):

The qsort() function is a modified partition-exchange sort, or quicksort.

Regardless of the naming, maybe it is right direction to place emphasis about the standard / posix requirement of qsort(). What do you all think ?

In D39723#904466, @zlei wrote:

I have to admit that I get bitten by the function name. I almost always treat qsort() as quicksort but it is actually a generic interface for sorting.
So it should be treated / named as sort() .

A second thought about this, I think for STD C or POSIX, use an implementation as standard is not scalable, as there're so many sorting algorithms.

From qsort(3):

The qsort() function is a modified partition-exchange sort, or quicksort.

Regardless of the naming, maybe it is right direction to place emphasis about the standard / posix requirement of qsort(). What do you all think ?

@zlei : ISO C apparently on defines one standard sorting function, and it is named qsort(), and the definition of performance is very loose.

@zlei : I'm doing some research if a pre-step for QuickSort, may be a solution to completely avoid QuickSort going O(N*N). If you want to join, let me know. Maybe I can put something up on GitHub.

--HPS

In D39723#904466, @zlei wrote:

I have to admit that I get bitten by the function name. I almost always treat qsort() as quicksort but it is actually a generic interface for sorting.
So it should be treated / named as sort() .

A second thought about this, I think for STD C or POSIX, use an implementation as standard is not scalable, as there're so many sorting algorithms.

From qsort(3):

The qsort() function is a modified partition-exchange sort, or quicksort.

Regardless of the naming, maybe it is right direction to place emphasis about the standard / posix requirement of qsort(). What do you all think ?

@zlei : ISO C apparently on defines one standard sorting function, and it is named qsort(), and the definition of performance is very loose.

@zlei : I'm doing some research if a pre-step for QuickSort, may be a solution to completely avoid QuickSort going O(N*N). If you want to join, let me know. Maybe I can put something up on GitHub.

I'm interested in that, although I'm not talent at algorithm ;)

--HPS