summaryrefslogtreecommitdiff
path: root/compiler/ghci/ByteCodeGen.hs
diff options
context:
space:
mode:
authorSimon Marlow <smarlow@fb.com>2016-07-21 04:51:05 -0700
committerSimon Marlow <marlowsd@gmail.com>2016-07-22 13:56:42 +0100
commit648fd73a7b8fbb7955edc83330e2910428e76147 (patch)
tree56b87ba9f03293c04fa892eb0435f8b87ddd377a /compiler/ghci/ByteCodeGen.hs
parentc4f3d91b6b32a27c2e00506de532e90c595de2d1 (diff)
downloadhaskell-648fd73a7b8fbb7955edc83330e2910428e76147.tar.gz
Squash space leaks in the result of byteCodeGen
When loading a large number of modules into GHCi, we collect CompiledByteCode for every module and then link it all at the end. Space leaks in the CompiledByteCode linger until we traverse it all for linking, and possibly longer, if there are bits we don't look at. This is the nuke-it-from-orbit approach: we deepseq the whole thing after code generation. It's the only way to be sure. Test Plan: Heap profile of GHCi while loading nofib/real/anna into GHCi, this patch reduces the peak heap usage from ~100M to ~50M. Reviewers: hvr, austin, bgamari, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2419
Diffstat (limited to 'compiler/ghci/ByteCodeGen.hs')
-rw-r--r--compiler/ghci/ByteCodeGen.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/ghci/ByteCodeGen.hs b/compiler/ghci/ByteCodeGen.hs
index 9c7d25a5ec..90e2174228 100644
--- a/compiler/ghci/ByteCodeGen.hs
+++ b/compiler/ghci/ByteCodeGen.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP, MagicHash, RecordWildCards #-}
+{-# OPTIONS_GHC -fprof-auto-top #-}
--
-- (c) The University of Glasgow 2002-2006
--
@@ -57,6 +58,7 @@ import UniqSupply
import Module
import Control.Arrow ( second )
+import Control.Exception
import Data.Array
import Data.Map (Map)
import Data.IntMap (IntMap)
@@ -93,10 +95,21 @@ byteCodeGen hsc_env this_mod binds tycs mb_modBreaks
dumpIfSet_dyn dflags Opt_D_dump_BCOs
"Proto-BCOs" (vcat (intersperse (char ' ') (map ppr proto_bcos)))
- assembleBCOs hsc_env proto_bcos tycs
+ cbc <- assembleBCOs hsc_env proto_bcos tycs
(case modBreaks of
Nothing -> Nothing
Just mb -> Just mb{ modBreaks_breakInfo = breakInfo })
+
+ -- Squash space leaks in the CompiledByteCode. This is really
+ -- important, because when loading a set of modules into GHCi
+ -- we don't touch the CompiledByteCode until the end when we
+ -- do linking. Forcing out the thunks here reduces space
+ -- usage by more than 50% when loading a large number of
+ -- modules.
+ evaluate (seqCompiledByteCode cbc)
+
+ return cbc
+
where dflags = hsc_dflags hsc_env
-- -----------------------------------------------------------------------------