[Haskell-beginners] State Transformer Confusion

Daniel Fischer daniel.is.fischer at web.de
Wed Feb 24 21:54:17 EST 2010


Am Donnerstag 25 Februar 2010 03:04:02 schrieb Chris Pettitt:
> Hello Haskell-Beginners,
>
> I'm having a fair amount of difficulty understanding the ST monad. In
> my basic experimentation I'm finding that I'm getting more heap
> allocated with STUArray than with a regular Array, which is not what I
> would expect.

And ordinarily you don't. The problem is that the STUArray suffers very 
badly from profiling. Compiling without -prof, the STUArray code allocates 
about half as much as the UArray code and takes ~42% of the time.
With profiling, STUArray allocates ~40% more and takes ~50% longer than 
UArray.

Two things:
- profiling interacts badly with some optimisations, so what the profiling 
output says may deviate significantly from what your -O2 compiled 
production code actually does
- some datatypes suffer more from profiling than others, so what the 
profiling output says for different choices of datatype may deviate 
significantly from how your -O2 compiled production code behaves

Normally, -prof doesn't change the behaviour very much, but sometimes it 
does.


>
> One additional point of confusion for me: when I run either function
> with +RTS -hc and use hp2ps I get an empty graph. I've seen these
> tools work quite well before, so I suspect I'm doing something wrong
> now.

Too little actual heap usage and too short running time. Change the upper 
limit to 10 million and you should get a graph with actual bands.

>
> Thanks,
> Chris



More information about the Beginners mailing list