[GHC] #5642: Deriving Generic of a big type takes a long time and lots of space

GHC ghc-devs at haskell.org
Sun Jun 5 17:19:52 UTC 2016


#5642: Deriving Generic of a big type takes a long time and lots of space
-------------------------------------+-------------------------------------
        Reporter:  basvandijk        |                Owner:  bgamari
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.3
      Resolution:                    |             Keywords:  deriving-
                                     |  perf, Generics
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Compile-time      |  Unknown/Multiple
  performance bug                    |            Test Case:  T5642
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D2304
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * differential:   => Phab:D2304


Comment:

 I've found a little trick to help reduce the constant factors in deriving
 `Generic`. (See Phab:D2304 for more details.) One can factor out the
 topmost `M1` from the derived definitions of `to` and `from` to reduce the
 number of times GHC has to typecheck an application of `M1`. This in turn
 leads to a reduction in the number of coercions, which lowers allocation.

 I tested this trick against basvandijk's 300-constructor datatype, and it
 saves almost 3 seconds of compilation time and uses ~6.4 times fewer
 coercions.

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


More information about the ghc-tickets mailing list