[Git][ghc/ghc][wip/js-memory] javascript: Read fields of ObjectBlock lazily

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Wed Oct 2 18:04:15 UTC 2024



Matthew Pickering pushed to branch wip/js-memory at Glasgow Haskell Compiler / GHC


Commits:
3ffc2f79 by Matthew Pickering at 2024-10-02T19:04:04+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

- - - - -


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/3ffc2f792408d64a6e37280521b895f264694ccd

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3ffc2f792408d64a6e37280521b895f264694ccd
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/20241002/2f3e802d/attachment-0001.html>


More information about the ghc-commits mailing list