Hi,

While using Michael Snoyman's persistent package, I discovered that a
certain bit of code generated from it made the GHC optimizer consume a
ridiculous amount of memory (ie. only when using the "-O" flag). I
know very little about the GHC compiler and Michael Snoyman
recommended I post my findings here to see what others thought.

I've done what I can to extract the code generated from the persistent
package and simplify/strip it down to the bare minimum of what's
needed to cause this issue. You can find it in the attachment
FromTest.hs. From my testing, removing five fields from Rec and the
equivalent from the fromValue function - the memory consumption drops
dramatically and I am able to compile.

For your convenience, I've also attached FromTest.out, which is the
output I get when compiling FromTest.hs using "ghc -O -v3". This is
just the output up to the point it starts consuming a lot of memory.
I've never seen anything after this point because my system slows down
to a crawl (due to swapping) and I end up killing the process.

Please let me know what you guys think or if you need any more
information about this. Thanks,
- Mike
module FromTest where

data FromType = FromType | OtherFromType

class Fromable a where
    from :: FromType -> Either String a 

instance (Fromable a) => Fromable (Maybe a) where
    from FromType = Right Nothing
    from x = case from x of
                Left y -> Left y
                Right z -> Right (Just z)

instance Fromable Int where
    from _ = Right 0

data Rec
    = Rec
      { recR0 :: (Maybe Int)
      , recR1 :: (Maybe Int)
      , recR2 :: (Maybe Int)
      , recR3 :: (Maybe Int)
      , recR4 :: (Maybe Int)
      , recR5 :: (Maybe Int)
      , recR6 :: (Maybe Int)
      , recR7 :: (Maybe Int)
      , recR8 :: (Maybe Int)
      , recR9 :: (Maybe Int)
      , recR10 :: (Maybe Int)
      , recR11 :: (Maybe Int)
      , recR12 :: (Maybe Int)
      , recR13 :: (Maybe Int)
      , recR14 :: (Maybe Int)
      , recR15 :: (Maybe Int)
      , recR16 :: (Maybe Int)
      , recR17 :: (Maybe Int)
      , recR18 :: (Maybe Int)
      , recR19 :: (Maybe Int)
      , recR20 :: (Maybe Int)
      }
    deriving (Show)

apE :: Either x (y -> z) -> Either x y -> Either x z
apE (Left x) _ = Left x
apE _ (Left x) = Left x
apE (Right f) (Right y) = Right $ f y

fromValue :: [FromType] -> Either String Rec
fromValue [x_105,
           x_106,
           x_107,
           x_108,
           x_109,
           x_110,
           x_111,
           x_112,
           x_113,
           x_114,
           x_115,
           x_116,
           x_117,
           x_118,
           x_119,
           x_120,
           x_121,
           x_122,
           x_123,
           x_124,
           x_125
          ] = (((((((((((((((((((((Right Rec
                                   `apE` from x_105)
                                  `apE` from x_106)
                                 `apE` from x_107)
                                `apE` from x_108)
                               `apE` from x_109)
                              `apE` from x_110)
                             `apE` from x_111)
                            `apE` from x_112)
                           `apE` from x_113)
                          `apE` from x_114)
                         `apE` from x_115)
                        `apE` from x_116)
                       `apE` from x_117)
                      `apE` from x_118)
                     `apE` from x_119)
                    `apE` from x_120)
                   `apE` from x_121)
                  `apE` from x_122)
                 `apE` from x_123)
                `apE` from x_124)
               `apE` from x_125)

Attachment: FromTest.out
Description: Binary data

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to