[Haskell-cafe] Long running Haskell program

David Leimbach leimy2k at gmail.com
Wed Nov 11 14:17:11 EST 2009

On Wed, Nov 11, 2009 at 9:51 AM, Bryan O'Sullivan <bos at serpentine.com>wrote:

> On Wed, Nov 11, 2009 at 7:43 AM, David Leimbach <leimy2k at gmail.com> wrote:
>> I recently ran into some serious space leak difficulties that would
>> ultimately cause this program to crash some time after startup (my simulator
>> is also written in Haskell, and runs a LOT faster than the real application
>> ever could, this has enabled me to fast forward a bit the data growth issues
>> and crash in minutes instead of days!)
> It sounds to me like you were storing a Map in a StateT. Since the usual
> State and StateT monads don't force the evaluation of their payload, I'm not
> terribly surprised that such a leak should arise.

That's exactly what was happening.  The system was being far too lazy (by
choices I made but didn't fully understand).

By pulling the Map out of the state, and pushing it back into the state, as
the definition of my looping, things got a lot better.

I didn't see another *easy* way to force the state to be evaluated, except
by doing IO on intermediate values.  seq will only evaluate strictly if it's
just underneath something else that's already been evaluated :-).  The
runtime doesn't look for "seq"s to force evaluation on.

I figured I was better off just creating a dependency in the evaluation,
near the outermost portion of the program (the loop) that would cause a
strict evaluation, and so far I was right :-)

Program behaves very well now, and responds much better too.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091111/1546f18d/attachment.html

More information about the Haskell-Cafe mailing list