[Git][ghc/ghc][wip/mpickering-hannes] Force inner_bh outside of unsafeInterleaveIO
Matthew Pickering (@mpickering)
gitlab at gitlab.haskell.org
Sat Mar 23 16:00:19 UTC 2024
Matthew Pickering pushed to branch wip/mpickering-hannes at Glasgow Haskell Compiler / GHC
Commits:
4ef9f2b1 by Matthew Pickering at 2024-03-23T15:59:39+00:00
Force inner_bh outside of unsafeInterleaveIO
This reduces the size of the FUN closure from 96 to 56 bytes.
Which saves ~12mb live bytes overall.
- - - - -
1 changed file:
- compiler/GHC/Utils/Binary.hs
Changes:
=====================================
compiler/GHC/Utils/Binary.hs
=====================================
@@ -1144,15 +1144,17 @@ lazyGet' :: HasCallStack => Maybe (IORef BinHandle) -> (Bin () -> BinHandle -> I
lazyGet' mbh f bh = do
p <- get @(Bin ()) bh -- a BinPtr
p_a <- tellBin bh
+ -- Do this before to avoid retaining reference to old BH inside the unsafeInterleaveIO.
+ let !get_inner_bh = maybe (pure bh) readIORef mbh
a <- unsafeInterleaveIO $ do
-- NB: Use a fresh off_r variable in the child thread, for thread
-- safety.
- inner_bh <- maybe (pure bh) readIORef mbh
+ inner_bh <- get_inner_bh
off_r <- newFastMutInt 0
let bh' = inner_bh { _off_r = off_r }
- seekBin bh' p_a
+ seekBinNoExpand bh' p_a
f p bh'
- seekBin bh p -- skip over the object for now
+ seekBinNoExpand bh p -- skip over the object for now
return a
-- | Serialize the constructor strictly but lazily serialize a value inside a
@@ -1282,6 +1284,8 @@ getGenericSymbolTable :: forall a. (Bin () -> BinHandle -> IO a) -> IORef BinHan
getGenericSymbolTable deserialiser bhRef bh = do
sz <- forwardGet bh (get bh) :: IO Int
mut_arr <- newArray_ (0, sz-1) :: IO (IOArray Int a)
+ -- Using lazyPut/lazyGet is quite space inefficient as each usage will allocate a large closure
+ -- (6 arguments-ish).
forM_ [0..(sz-1)] $ \i -> do
f <- lazyGet' (Just bhRef) deserialiser bh
writeArray mut_arr i f
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4ef9f2b17f1ef12e735475a21c99564135176632
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4ef9f2b17f1ef12e735475a21c99564135176632
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/20240323/3316de7c/attachment-0001.html>
More information about the ghc-commits
mailing list