summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Klebinger <klebinger.andreas@gmx.at>2020-06-22 19:33:04 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-07-14 21:31:27 -0400
commit64c774b043a2d9be3b98e445990c795f070dab3f (patch)
treea836a8eaa844d8478a6a9041fcc7e47aac6190f8
parent118e1c3da622f17c67b4e0fbc12ed7c7084055dc (diff)
downloadhaskell-64c774b043a2d9be3b98e445990c795f070dab3f.tar.gz
Explain why keeping DynFlags in AnalEnv saves allocation.
-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]