Hello, I'm using ghc 7.10.1 to compile OpenGLRaw which is now impossible with -O1 and -O2 due to "ghc : out of memory error" on a 4GB linux host. The file making memory explode is Graphics.Rendering.OpenGL.Raw.Functions. With -O0 it uses 600 MB.
The file is really huge, but I could compile it with prior versions of ghc.
I've had a look and indeed the file takes way more memory to compile with HEAD. Looking at the heap profiles, it seems that the problem is in GHC itself (space leak somewhere?). I'll attach the heap profiles (from compiling the single module itself, i.e., touching the file and running prof GHC on it).
Paolo also says: ere is another file , which is small, which cannot be compiled within 4GB memory.
I've had another quick look at this and compiled profiled GHC with addition of {-# OPTIONS_GHC -fprof-auto #-} to simplCore/Simplify.hs. The results are interesting:
Looking at git blame the Simplify.simplCast didn't change much recently... Next week I'll try to have a look at Core generated by 7.8.4 and HEAD (maybe some stage before simplifier generates something weird?).
I created a synthetic test case that exhibits the same space blow-up:
modu = unlines $ "module Out where" : "import Control.Monad (forever)" : [ var ++ " :: IO (); " ++ var ++ " = forever $ putStrLn \"" ++ var ++ "\"" | n <- [1..3000], let var = "a" ++ show n ]main = writeFile "Out.hs" modu
The string literals seem to be important, I didn't manage to find a variation that blew up without them.
Sven Panne says: To alleviate the pain a bit, I've uploaded a new version of OpenGLRaw
(2.5.0.0) to Hackage, containing 2 improvements:
foreign import "dynamic"s with the same signature are re-used, cutting down their number from 3062 to 864.
Those foreign import "dynamic"s live in a separate module now.
Travis CI seems to be happy with these changes (the VMs there don't have much memory, either), although Haddock still seems to eat memory like hell. But that's a different story...
I had a brief look at generated Core (for both 7.8.4 and HEAD) and couldn't really find anything suspicious. Also core stats seem similar -- we generate almost identical number of terms/types/coercions. (although I'm far from an expert so take that with a grain of salt)
The good news is that I managed to narrow it down to b8392ae7
What I did: initially I just wanted to bisect but couldn't really get GHC to build before Jan 2015. So I checkout a commit from early January (the problem is reproducible there) and reverted the above patch (at which point the problem is no longer reproducible).