[Haskell-cafe] Why does my module take so long to compile?

Troels Henriksen athas at sigkill.dk
Mon Feb 15 17:20:55 UTC 2021


Carter Schonwald <carter.schonwald at gmail.com> writes:

> How big are your data types in the file In question? Do you ghc generics or
> deriving or template Haskell? Could you share a link to the file in
> question ?

The file does not define any large data types itself, but it operates on
some fairly large data types (an AST, it's a compiler).  But so do many
other modules that work just fine.  It uses no generics, nontrivial
deriving, or Template Haskell.  It's this file:
https://github.com/diku-dk/futhark/blob/master/src/Futhark/Pass/ExtractKernels/DistributeNests.hs

I also found a handful of other modules in my project that are
significantly slower to compile in GHC 8.10, and seemingly also because
of the desugarer, but none of them have any obvious smoking guns like
generics or TH.

The only commonality I can find is that the affected modules contain
functions with a relatively large typeclass context.  I use
ConstraintKinds to make them more concise, and I guess unfolded there
may be 30-40 equality/class constraints in total.  Like this:

    type DistLore lore =
      ( Bindable lore,
        HasSegOp lore,
        BinderOps lore,
        LetDec lore ~ Type,
        ExpDec lore ~ (),
        BodyDec lore ~ ()
      )

where the 'Bindable' constraint in particular then implies a further
handful of "~" constraints:

    class
      ( ASTLore lore,
        FParamInfo lore ~ DeclType,
        LParamInfo lore ~ Type,
        RetType lore ~ DeclExtType,
        BranchType lore ~ ExtType,
        SetType (LetDec lore)
      ) =>
      Bindable lore
      where
      ...

FParamInfo/LParamInfo/etc are type families.  Are such constraints
particularly slow?

-- 
\  Troels
/\ Henriksen


More information about the Haskell-Cafe mailing list