[GHC] #12234: 'deriving Eq' on recursive datatype makes ghc eat a lot of CPU and RAM

GHC ghc-devs at haskell.org
Wed Nov 30 18:59:16 UTC 2016


#12234: 'deriving Eq' on recursive datatype makes ghc eat a lot of CPU and RAM
-------------------------------------+-------------------------------------
        Reporter:  slyfox            |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:  deriving-perf
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Compile-time      |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * cc: RyanGlScott (added)


Comment:

 Yikes.

 Interestingly, the way the `Eq (Fix f)` instance is constructed plays a
 large role in the slowdown. Since it's a newtype, GHC defaults to deriving
 that instance via `GeneralizedNewtypeDeriving`, i.e.,

 {{{#!hs
 instance Eq (f (Fix f)) => Eq (Fix f) where
   (==) = coerce ((==) :: f (Fix f) -> f (Fix f) -> Bool) :: Fix f -> Fix f
 -> Bool
 }}}

 But if you implement it the "stock" way, i.e.,

 {{{#!hs
 instance Eq (f (Fix f)) => Eq (Fix f) where
   In x == In y = x == y
 }}}

 Then it compiles instantly. So perhaps the coercion solver is to blame
 here?

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


More information about the ghc-tickets mailing list