Opened 9 months ago

Closed 8 months ago

#14524 closed bug (wontfix)

Use sortOn instead of sortWith

Reported by: AndreasK Owned by: AndreasK
Priority: normal Milestone:
Component: Compiler Version: 8.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4233
Wiki Page:


sortWithprovides the same functionality as sortOn from Data.List.

As sortOn is already part of Prelude it makes sense for the GHC source to use it as well.

Change History (3)

comment:1 Changed 9 months ago by nomeata

SortOn is there since 4.8, which, according to corresponds to GHC-7.10.1 – oh yes, this is definitely around for long enough. A differential revision with that change is will probably be well-received.

comment:2 Changed 9 months ago by AndreasK

Differential Rev(s): Phab:D4233
Owner: set to AndreasK

comment:3 Changed 8 months ago by AndreasK

Resolution: wontfix
Status: newclosed

The patch increased allocations (slightly) when compiling files.

Doing a quick benchmark to check if/how much faster it is showed that:

sortWith is at least still faster when the given function is a simple pattern match like the function below for any reasonably sized list. When testing up to 500 000 elements sortWith beat sortOn by >10% consistently.

Even more so when it's just a selector like \(a,_,_) -> a.

f:: T -> T -> T -> Int
f _ A A = 1
f B _ _ = 2
f C _ C = 3
f D _ _ = 4
f _ C B = 7
f A E A = 8
f _ _ _ = 5

So using sortWith by default in GHC is the right call.

Note: See TracTickets for help on using tickets.