Cost of Overloading vs. HOFs

Simon Peyton-Jones simonpj at
Mon May 7 04:28:58 EDT 2007

| The GHC users guide says overloading "is death to performance if
| left to linger in an inner loop" and one thing I noticed while
| playing about with the AVL lib was that using a HOF and passing
| the (overloaded) compare function as an explicit argument at the
| start seemed to give noticable a performance boost (compared with
| dictionary passing presumably).

GHC does try to optimise the task of selecting a method out of a dictionary. However optimisation is a delicate art, especially when you are looking at inner loops.  It may well be that GHC screws up because of some apparently minor change.   The thing to do is to look at the Core (-ddump-simpl) for your inner loop and see what the difference is.

(Even then, it's not always straightforward to design optimisations that hit your case without harming someone else.   But it's usually fun.)


More information about the Glasgow-haskell-users mailing list