summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Klebinger <klebinger.andreas@gmx.at>2020-06-22 19:33:04 +0200
committerAndreas Klebinger <klebinger.andreas@gmx.at>2020-07-05 20:40:33 -0400
commit2856bbe1ffd06a5ed0b721a2a89b4c4cc1b9a494 (patch)
treeebaee99bbaba074495c026d7e6e2033945384812
parent7aa6ef110d8cc6626b1cf18d85a37cbac53e2795 (diff)
downloadhaskell-wip/andreask/dmdAnal_dflags.tar.gz
Explain why keeping DynFlags in AnalEnv saves allocation.wip/andreask/dmdAnal_dflags
-rw-r--r--compiler/GHC/Core/Opt/DmdAnal.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler/GHC/Core/Opt/DmdAnal.hs b/compiler/GHC/Core/Opt/DmdAnal.hs
index e5d9c9a0d9..7f4327591e 100644
--- a/compiler/GHC/Core/Opt/DmdAnal.hs
+++ b/compiler/GHC/Core/Opt/DmdAnal.hs
@@ -1179,8 +1179,26 @@ type DFunFlag = Bool -- indicates if the lambda being considered is in the
notArgOfDfun :: DFunFlag
notArgOfDfun = False
+{- Note [dmdAnalEnv performance]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+It's tempting to think that removing the dynflags from AnalEnv would improve
+performance. After all when analysing recursive groups we end up allocating
+a lot of environments. However this is not the case.
+
+We do get some performance by making AnalEnv smaller. However very often we
+defer computation which means we have to capture the dynflags in the thunks
+we allocate. Doing this naively in practice causes more allocation than the
+removal of DynFlags saves us.
+
+In theory it should be possible to make this better if we are stricter in
+the analysis and therefore allocate fewer thunks. But I couldn't get there
+in a few hours and overall the impact on GHC here is small, and there are
+bigger fish to fry. So for new the env will keep a reference to the flags.
+-}
+
data AnalEnv
- = AE { ae_dflags :: DynFlags
+ = AE { ae_dflags :: DynFlags -- See Note [dmdAnalEnv performance]
, ae_sigs :: SigEnv
, ae_virgin :: Bool -- True on first iteration only
-- See Note [Initialising strictness]