[reactive] whenE uses much memory

Conal Elliott conal at conal.net
Tue Aug 24 04:17:34 EDT 2010

Oops.  The list's spam-filter tossed this note.

---------- Forwarded message ----------
From: Alexander Foremny <alexanderforemny at googlemail.com>
To: reactive at haskell.org
Date: Tue, 24 Aug 2010 10:14:11 +0200
Subject: whenE uses much memory

I am trying to write a simple 2D tower defense game using reactive and
reactive-glut. I am spawning a wave of creeps that walk around the map
and when there are no creeps on the map, I'd like to spawn the next
wave. However, I cannot predict at which time there will be no creeps
on the maps since each creature might move with different speed. To
realize switching anyway I thought I could poll the number of creeps
and switch when the number is zero. With that solution I am having
serious performance problems. Here's the relevant code:

> data World = World { ... }
> wave1 :: Behavior World
> wave2 :: Behavior World
> worldB = wave1 `switcher` fmap (const wave2) (whenE (zeroCreeps wave1)
>     where pollE = atTimes [1..]
> zeroCreeps :: Behavior World -> Behavior Bool

When running worldB from main I can see the program's memory usage
increasing and everything becomes very unresponsive. It seems as if
whenE is accumalating all the occurences of the event. The problem
seems to boil down to snapshot having the same behavior.

> snapshot (pure False) (atTimes [1..])

This piece of code uses very much memory either. Is this due to
reactive being broken (I read that somewhere) or is my solution just
no solution at all?

I am using ghc 6.12.1 with reactive 0.11.5 and reactive-glut 0.1.9.

Alexander Foremny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/reactive/attachments/20100824/3c921858/attachment.html

More information about the Reactive mailing list