[Haskell-cafe] Re: Suspected stupid Haskell Question

Justin Bailey jgbailey at gmail.com
Fri Oct 19 13:13:58 EDT 2007

On 10/17/07, Thomas Hartman <thomas.hartman at db.com> wrote:
> Is there a more scientific way of figuring out if one version is better
> than the other by using, say profiling tools?

Profiling Haskell programs is black magic, but of the sort you learn by
having a problem to solve. I don't think it requires special genius, just
enough motivation. Profiling the interpreter my team created during the ICFP
contest did that to me.

The GHC heap profiler looked weird to me at first because you are required
to convert its output to a PostScript file. However, it's well worth doing.
There are several types of profiles, but you would probably be most
interested in the "biographical" profile. The GHC documentation is pretty
good and the article "Heap Profiling for Space Efficiency"[1] may also help.
The article was written for the nhc compiler but the tools look the same.

Performance profiling is easier - it's just dumped as text output when your
program runs. GHC's documentation is really good here. One thing I've
learned is to look for two things:

  1) Functions that do allocations and execute many times
  2) Functions that run lots of times

#2 is pretty much universal for profiling, but #1 is unique to Haskell (and
probably any pure functional language).

Sadly none of these technique work for stack overflows. Or, more likely, I
haven't learned how to spot them. Luckily the culprit is usually a fold that
isn't strict enough. Albert's post about the Bird book is a good pointer. I
just read that chapter myself last night, and he gives a very clear
explanation of how lazy evaluation works (he calls it 'outermost reduction')
and how strictness interacts with laziness.

Hope that helps!


[1] http://citeseer.ist.psu.edu/runciman96heap.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071019/36b0c3e3/attachment-0001.htm

More information about the Haskell-Cafe mailing list