[Git][ghc/ghc][master] Eliminate thunk in 'IfaceTyCon'
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Tue Mar 19 18:51:20 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
349ea330 by Fendor at 2024-03-19T14:50:00-04:00
Eliminate thunk in 'IfaceTyCon'
Heap analysis showed that `IfaceTyCon` retains a thunk to
`IfaceTyConInfo`, defeating the sharing of the most common instances of
`IfaceTyConInfo`.
We make sure the indirection is removed by adding bang patterns to
`IfaceTyCon`.
Experimental results on the agda code base, where the `mi_extra_decls`
were read from disk:
Before this change, we observe around 8654045 instances of:
`IfaceTyCon[Name,THUNK_1_0]`
But these thunks almost exclusively point to a shared value!
Forcing the thunk a little bit more, leads to `ghc-debug` reporting:
`IfaceTyCon[Name:Name,IfaceTyConInfo]`
and a noticeable reduction of live bytes (on agda ~10%).
- - - - -
1 changed file:
- compiler/GHC/Iface/Type.hs
Changes:
=====================================
compiler/GHC/Iface/Type.hs
=====================================
@@ -93,6 +93,7 @@ import {-# SOURCE #-} GHC.Tc.Utils.TcType ( isMetaTyVar, isTyConableTyVar )
import Data.Maybe( isJust )
import qualified Data.Semigroup as Semi
import Control.DeepSeq
+import Control.Monad ((<$!>))
{-
************************************************************************
@@ -244,7 +245,18 @@ instance Monoid IfaceAppArgs where
-- We have to tag them in order to pretty print them
-- properly.
data IfaceTyCon = IfaceTyCon { ifaceTyConName :: IfExtName
- , ifaceTyConInfo :: IfaceTyConInfo }
+ , ifaceTyConInfo :: !IfaceTyConInfo
+ -- ^ We add a bang to this field as heap analysis
+ -- showed that this constructor retains a thunk to
+ -- a value that is usually shared.
+ --
+ -- See !12200 for how this bang saved ~10% residency
+ -- when loading 'mi_extra_decls' on the agda
+ -- code base.
+ --
+ -- See Note [Sharing IfaceTyConInfo] for why
+ -- sharing is so important for 'IfaceTyConInfo'.
+ }
deriving (Eq)
-- | The various types of TyCons which have special, built-in syntax.
@@ -2050,7 +2062,13 @@ instance Binary IfaceTyConSort where
instance Binary IfaceTyConInfo where
put_ bh (IfaceTyConInfo i s) = put_ bh i >> put_ bh s
- get bh = mkIfaceTyConInfo <$> get bh <*> get bh
+ get bh = mkIfaceTyConInfo <$!> get bh <*> get bh
+ -- We want to make sure, when reading from disk, as the most common case
+ -- is supposed to be shared. Any thunk adds an additional indirection
+ -- making sharing less useful.
+ --
+ -- See !12200 for how this bang and the one in 'IfaceTyCon' reduces the
+ -- residency by ~10% when loading 'mi_extra_decls' from disk.
instance Outputable IfaceTyLit where
ppr = pprIfaceTyLit
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/349ea3302bd81daa896e0541b6b8e34a5da16b52
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/349ea3302bd81daa896e0541b6b8e34a5da16b52
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/20240319/7d8436bd/attachment-0001.html>
More information about the ghc-commits
mailing list