profiling for stack usage

Alastair Reid alastair@reid-consulting-uk.ltd.uk
Fri, 15 Aug 2003 16:17:37 +0100


> I'm currently in a situation where my program runs easily out of
> stack.  Depending on the input, stack usage often exceeds 10Mb.

I have better than 75% success locating the source of these bugs with the 
following command:

  grep '+1' *.hs *.lhs

Reason: Lazy arithmetic can easily cause you to build thunks that look like 
this:

   1+1+1+1+ .... + 1 + 0

which take O(n) heap to store and O(n) stack to evaluate (with constant 
factors of around 10-20).

If you've already tried this approach, the tolols SimonM mentions are well 
worth using.

--
Alastair Reid