[GHC] #9557: Deriving instances is slow

GHC ghc-devs at haskell.org
Mon Sep 22 08:59:04 UTC 2014


#9557: Deriving instances is slow
-------------------------------------+-------------------------------------
              Reporter:  Feuerbach   |            Owner:
                  Type:  bug         |           Status:  new
              Priority:  normal      |        Milestone:
             Component:  Compiler    |          Version:  7.8.3
            Resolution:              |         Keywords:
      Operating System:              |     Architecture:  Unknown/Multiple
  Unknown/Multiple                   |       Difficulty:  Unknown
       Type of failure:              |       Blocked By:
  None/Unknown                       |  Related Tickets:  #8731
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by nomeata):

 > Study the generated code to see if it could be abstracted, so that
 instead of lots of code, there were calls to some suitable shared
 functions.

 Looking at the `Ord` code (which seems to be the largest):
  * It seems that it could be made much smaller using `<>` (which is `EQ <>
 x = x` and `y <> _ = y` otherwise) instead of nested case expressions. I
 guess there would be a performance hit, though.
  * Do we really have to provide separate definitions for `compare` and `<`
 and `<=` and `>` and `>=`? Maybe using the default implementation for all
 methods but `compare` is good enough, and could bring code size down
 considerably.

 Overreaching spontaneous idea: Add a method `generalCompare :: r -> r -> r
 -> a -> a -> r` to the `Ord` class. Implement that in deriving clauses,
 and have the default implementations use that. (e.g. `(<) = generalCompare
 True False False`). Should be faster than using `compare` + pattern
 matching. OTOH. all constructors of `Comparing` are static values, so
 there is probably not much to win here.

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


More information about the ghc-tickets mailing list