[GHC] #15176: Superclass `Monad m =>` makes program run 100 times slower
GHC
ghc-devs at haskell.org
Tue Sep 4 13:20:40 UTC 2018
#15176: Superclass `Monad m =>` makes program run 100 times slower
-------------------------------------+-------------------------------------
Reporter: danilo2 | Owner: osa1
Type: bug | Status: new
Priority: highest | Milestone: 8.8.1
Component: Compiler | Version: 8.4.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by osa1):
So, I've built two versions of the package with `-dump-simpl -dump-to-file
-dsuppress-uniques` (which took about an hour to build twice on my
i7-8700K desktop). Unfortunately there are 71 modules in this package and
none of the files are identical between two versions (there are at least
very minor identifier changes) so this is still not easy to debug, but
while checking some random files I found some relevant changes between two
versions:
This expression in the original version:
{{{
$dLayersFoldableBuilder__
`cast` (Data.Graph.Fold.Layer.N:LayersFoldableBuilder__[0]
<t>_N <layers>_N <m>_N
:: (LayersFoldableBuilder__ t layers m :: Constraint)
~R# (SomePtr -> m (Fold.Result t) -> m (Fold.Result t) :: *))
}}}
becomes this after `Monad =>`:
{{{
buildLayersFold__
@ t
@ layers
@ m
$dLayersFoldableBuilder__
}}}
If my understanding is correct, in the original version the typeclass
dictionary is represented as its method, but with `Monad m =>` it's not as
it not has one more field for the `Monad m` dictionary. This means one
layer of indirection in the `Monad m =>` version.
There are lots of changes similar to this. Not sure if this by itself
explains 20x increase in runtime though.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15176#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list