[GHC] #14941: Switching direct type family application to EqPred (~) prevents inlining in code using vector (10x slowdown)

GHC ghc-devs at haskell.org
Thu Sep 20 00:40:59 UTC 2018


#14941: Switching direct type family application to EqPred (~) prevents inlining in
code using vector (10x slowdown)
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:  davide
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.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 nh2):

 Replying to [comment:9 simonpj]:
 > How important is it?  I'm tempted to say "don't write types like that"!

 From the user's perspective, I can put forward two use cases:

 1. Type level let bindings

   `(..., VG.Mutable v ~ vm) => ... -> vm (PrimState m) e -> ...`

   From the issue description. This is essentially type-signature
 `let`-binding, allowing me to write the type signature more
 clearly/legibly, especially if `vm` is used multiple times.

 2. Refactorings

   For the code in comment 4, `(val ~ Int) =>`, this arose from a
 refactoring where I replaced `Int` by `val` across a large code base, and
 then in the top-level-ish function set `val ~ Int` to check if the
 performance was unimpacted.

 I'd probably be OK without this being fixed, now that I know what's going
 on, but if it's not fixed, we somehow have to do a much better job at
 giving warnings or educating people that you can't just apply a
 substitution principle when "cleaning up" type signaturees with `~`. I
 incorrectly assumed this would be type-level only, and as a result had to
 start a multi-day investigation of where my performance went because I
 expected any mistake on my side but not this. Especially when writing code
 using `vector` whose type family heavy API, in my opinion, almost begs for
 `~` to be used to achieve readable signatures.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14941#comment:10>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list