binary icon indicating copy to clipboard operation
binary copied to clipboard

Generic deriving of Binary instances with -O blows up compilation time

Open ezyang opened this issue 9 years ago • 2 comments

Here's the file:

{-# LANGUAGE DeriveGeneric #-}

module Deriv where

import GHC.Generics

data T = T {
    f0 :: String,
    f1 :: String,
    f2 :: String,
    f3 :: String,
    f4 :: String,
    f5 :: String,
    f6 :: String,
    f7 :: String,
    f8 :: String,
    f9 :: String,
    f10 :: String,
    f11 :: String,
    f12 :: String,
    f13 :: String,
    f14 :: String,
    f15 :: String,
    f16 :: String,
    f17 :: String,
    f18 :: String,
    f19 :: String,
    f20 :: String,
    f21 :: String,
    f22 :: String,
    f23 :: String,
    f24 :: String,
    f25 :: String,
    f26 :: String,
    f27 :: String,
    f28 :: String,
    f29 :: String,
    f30 :: String,
    f31 :: String,
    f32 :: String,
    f33 :: String,
    f34 :: String,
    f35 :: String,
    f36 :: String,
    f37 :: String,
    f38 :: String,
    f39 :: String
    }
    deriving (Generic)

instance Binary T
ezyang@sabre:~/Dev/labs$ time $DEV/ghc-7.10-frontend-plugins/usr/bin/ghc --make Deriv.hs -O0 -fforce-recomp
[1 of 1] Compiling Deriv            ( Deriv.hs, Deriv.o )

real    0m0.873s
user    0m0.756s
sys 0m0.108s
ezyang@sabre:~/Dev/labs$ time $DEV/ghc-7.10-frontend-plugins/usr/bin/ghc --make Deriv.hs -O -fforce-recomp
[1 of 1] Compiling Deriv            ( Deriv.hs, Deriv.o )

real    0m7.480s
user    0m7.256s
sys 0m0.184s

Who knows if this is a GHC or binary problem. I just want it fixed >:-)

BTW, explicit field names exacerbate the problem by doubling the compile time.

ezyang avatar Dec 17 '15 20:12 ezyang

Here's the corresponding GHC bug: https://ghc.haskell.org/trac/ghc/ticket/9630

ezyang avatar Dec 17 '15 20:12 ezyang

I suspect that it's binary. It tries to be aggressive about inlining - a poor strategy that requires a lot of maintenance for every new GHC version.

kolmodin avatar Dec 17 '15 23:12 kolmodin