[Git][ghc/ghc][wip/js-memory] javascript: Read fields of ObjectBlock lazily
Matthew Pickering (@mpickering)
gitlab at gitlab.haskell.org
Thu Oct 3 08:48:28 UTC 2024
Matthew Pickering pushed to branch wip/js-memory at Glasgow Haskell Compiler / GHC
Commits:
78d27ee2 by Matthew Pickering at 2024-10-03T09:47:47+01:00
javascript: Read fields of ObjectBlock lazily
When linking a module with a large dependency footprint too much of the
object files were forced during linking. This lead to a large amount of
memory taken up by thunks which would never be forced
On the PartialDownsweep test this halves the memory required (from 25G
to 13G).
Towards #25324
-------------------------
Metric Increase:
size_hello_obj
-------------------------
- - - - -
2 changed files:
- compiler/GHC/StgToJS/Object.hs
- compiler/GHC/StgToJS/Types.hs
Changes:
=====================================
compiler/GHC/StgToJS/Object.hs
=====================================
@@ -255,23 +255,23 @@ instance Outputable ExportedFun where
-- index
putObjBlock :: WriteBinHandle -> ObjBlock -> IO ()
putObjBlock bh (ObjBlock _syms b c d e f g) = do
- put_ bh b
- put_ bh c
+ lazyPut bh b
+ lazyPut bh c
lazyPut bh d
- put_ bh e
- put_ bh f
- put_ bh g
+ lazyPut bh e
+ lazyPut bh f
+ lazyPut bh g
-- | Read an ObjBlock and associate it to the given symbols (that must have been
-- read from the index)
getObjBlock :: [FastString] -> ReadBinHandle -> IO ObjBlock
getObjBlock syms bh = do
- b <- get bh
- c <- get bh
+ b <- lazyGet bh
+ c <- lazyGet bh
d <- lazyGet bh
- e <- get bh
- f <- get bh
- g <- get bh
+ e <- lazyGet bh
+ f <- lazyGet bh
+ g <- lazyGet bh
pure $ ObjBlock
{ oiSymbols = syms
, oiClInfo = b
=====================================
compiler/GHC/StgToJS/Types.hs
=====================================
@@ -312,13 +312,13 @@ data LinkableUnit = LinkableUnit
-- | one toplevel block in the object file
data ObjBlock = ObjBlock
- { oiSymbols :: ![FastString] -- ^ toplevel symbols (stored in index)
- , oiClInfo :: ![ClosureInfo] -- ^ closure information of all closures in block
- , oiStatic :: ![StaticInfo] -- ^ static closure data
+ { oiSymbols :: [FastString] -- ^ toplevel symbols (stored in index)
+ , oiClInfo :: [ClosureInfo] -- ^ closure information of all closures in block
+ , oiStatic :: [StaticInfo] -- ^ static closure data
, oiStat :: Sat.JStat -- ^ the code
- , oiRaw :: !BS.ByteString -- ^ raw JS code
- , oiFExports :: ![ExpFun]
- , oiFImports :: ![ForeignJSRef]
+ , oiRaw :: BS.ByteString -- ^ raw JS code
+ , oiFExports :: [ExpFun]
+ , oiFImports :: [ForeignJSRef]
}
data ExpFun = ExpFun
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/78d27ee2f4df35ea320c35355ddf67fee52d7073
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/78d27ee2f4df35ea320c35355ddf67fee52d7073
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241003/d12c018d/attachment-0001.html>
More information about the ghc-commits
mailing list