Performance-loss of accessing data through class?

Peter Simons simons at
Thu Oct 14 07:49:27 EDT 2004

Simon Marlow writes:

 >>> class KnowsMyStuff a where
 >>> foo :: a -> Int
 >>> bar :: a -> Float
 >>> etc :: a -> [String]
 >> If I did that, how much performance would I lose?

 > If your code is using a method from a known instance of a
 > class, and the method has a small enough definition, then
 > chances are good that it'll get inlined and the extra
 > layer of abstraction will dissappear. I'm guessing this
 > is the case with your example.

Great, that's good to hear.

 > We always enjoy investigating benchmarks, so if you have
 > some code you think isn't going fast enough, then post it
 > here and we'll help you find out where the performance
 > problems are.

Alright, thanks for the offer. I'll certainly do that when I
notice anything. So far, I am pleased to say that the
performance is better than I had expected, actually. That
doesn't happen very often. :-)


More information about the Glasgow-haskell-users mailing list