GHC profiling is not that hard. There are a few tutorials on the Internet that can help you (try <a href="http://book.realworldhaskell.org/read/profiling-and-optimization.html">Real World Haskell, ch 25</a> )<br><br>Running your code with "+RTS -pa -sstderr" can give you some hints on where it is hogging memory.<br>
<br>Regards.<br><br>Rafael<br><br><div class="gmail_quote">On Wed, Apr 27, 2011 at 15:25, Patrick LeBoutillier <span dir="ltr"><<a href="mailto:patrick.leboutillier@gmail.com">patrick.leboutillier@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Felipe,<br>
<br>
I tried the $! bit, but I get the same result. I guess there's another<br>
leak somewhere...<br>
<br>
Patrick<br>
<br>
On Wed, Apr 27, 2011 at 11:20 AM, Felipe Almeida Lessa<br>
<<a href="mailto:felipe.lessa@gmail.com">felipe.lessa@gmail.com</a>> wrote:<br>
> On Wed, Apr 27, 2011 at 11:52 AM, Patrick LeBoutillier<br>
> <<a href="mailto:patrick.leboutillier@gmail.com">patrick.leboutillier@gmail.com</a>> wrote:<br>
>> How do I figure out why the program needs a lot of stack?<br>
><br>
> Usually it is because you are building a large thunk.<br>
><br>
>> Also, is there an easy way to increace performance?<br>
><br>
> Getting rid of the thunks should increase performance as well.<br>
><br>
> I've had just a quick look on your code, but here are some suggestions:<br>
><br>
>> record :: (Ord n) => n -> Distrib n -> Distrib n<br>
>> record n (Distrib m rs) = Distrib (M.alter f slot m) rs<br>
>> where f (Just n) = Just $ n + 1<br>
>> f Nothing = Just 1<br>
>> slot = findSlot n rs<br>
>> findSlot x (r@(Range a b):rs)<br>
>> | x >= a && x < b = r<br>
>> | otherwise = findSlot x rs<br>
>> findSlot x [] = OutOfBounds<br>
><br>
> Try changing "Just $ n + 1" to "Just $! n + 1". It is possible that<br>
> this change alone removes the leak (it is the only obvious leak I'm<br>
> seeing right now).<br>
><br>
> Also, for findSlot you may want to do a binary search, but that isn't<br>
> related to the leak at all.<br>
><br>
> Cheers,<br>
><br>
> --<br>
> Felipe.<br>
><br>
<br>
<br>
<br>
--<br>
=====================<br>
Patrick LeBoutillier<br>
Rosemère, Québec, Canada<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Rafael Gustavo da Cunha Pereira Pinto<br><br>