[GHC] #14524: Use sortOn instead of sortWith

GHC ghc-devs at haskell.org
Mon Dec 4 20:31:10 UTC 2017


#14524: Use sortOn instead of sortWith
-------------------------------------+-------------------------------------
        Reporter:  AndreasK          |                Owner:  AndreasK
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.1
      Resolution:  wontfix           |             Keywords:
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:                    |
-------------------------------------+-------------------------------------
Changes (by AndreasK):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 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.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14524#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list