Cost of Overloading vs. HOFs

Neil Mitchell ndmitchell at gmail.com
Fri May 4 16:02:03 EDT 2007


Hi Adrian

> 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).
>
> I'm not sure why that should be, but has anyone else noticed this?

A HOF is one box, the Ord dictionary is an 8-box tuple containing HOF
boxes. When you invoke compare out of Ord, you are taking something
out of the tuple, whereas when you use the HOF its directly there.

This is also the reason you get a performance decrease moving from a
1-element class to a 2-element class.

Thanks

Neil


More information about the Glasgow-haskell-users mailing list