ghc -O2 and class dictionaries

Simon Peyton-Jones simonpj at microsoft.com
Mon Dec 29 09:23:38 EST 2008


Which version of GHC are you using?  GHC 6.10 implements automatically precisely the transformation you give below.

If the difference shows up in GHC 6.10, could you spare a moment to produce a reproducible test case, and record it in GHC's bug tracker?

Thanks

Simon

| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of Dave Bayer
| Sent: 28 December 2008 15:29
| To: glasgow-haskell-users at haskell.org
| Subject: ghc -O2 and class dictionaries
|
| Using "ghc -O2" while tuning a class instance for performance, I
| obtained a 13% speedup by applying the transformation
|
| >   instance (Ord a, Num b) ⇒ Sum PSum a b where
| >     empty      = empty
| >     insert     = insert
| >     union      = union
| >     unions     = unions
| >     extractMin = extractMin
| >     fromList   = fromList
| >     toList     = toList
| >     map        = map
| >     mapMaybe   = mapMaybe
|
| and defining the instance functions outside the instance declaration,
| rather than inside the instance declaration.
|
| Conceptually, I understand this as follows: After this transformation,
| none of the recursive calls have to go through the class dictionary.
|
| Is this a transformation that ghc could automatically apply while
| optimizing? It is clear at compile time that the recursive calls are
| from this instance. Every 13% helps.
|
| (My example is adapting a pairing heap to sums of terms, e.g. to
| define an algebra from a small category. So far, I can't beat
| Data.Map, but I'm not done tuning. Other examples might not show the
| same performance increase from this transformation.)
|
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



More information about the Glasgow-haskell-users mailing list