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 &quot;+RTS -pa -sstderr&quot; 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">&lt;<a href="mailto:patrick.leboutillier@gmail.com">patrick.leboutillier@gmail.com</a>&gt;</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&#39;s another<br>
leak somewhere...<br>
<br>
Patrick<br>
<br>
On Wed, Apr 27, 2011 at 11:20 AM, Felipe Almeida Lessa<br>
&lt;<a href="mailto:felipe.lessa@gmail.com">felipe.lessa@gmail.com</a>&gt; wrote:<br>
&gt; On Wed, Apr 27, 2011 at 11:52 AM, Patrick LeBoutillier<br>
&gt; &lt;<a href="mailto:patrick.leboutillier@gmail.com">patrick.leboutillier@gmail.com</a>&gt; wrote:<br>
&gt;&gt; How do I figure out why the program needs a lot of stack?<br>
&gt;<br>
&gt; Usually it is because you are building a large thunk.<br>
&gt;<br>
&gt;&gt; Also, is there an easy way to increace performance?<br>
&gt;<br>
&gt; Getting rid of the thunks should increase performance as well.<br>
&gt;<br>
&gt; I&#39;ve had just a quick look on your code, but here are some suggestions:<br>
&gt;<br>
&gt;&gt; record :: (Ord n) =&gt; n -&gt; Distrib n -&gt; Distrib n<br>
&gt;&gt; record n (Distrib m rs) = Distrib (M.alter f slot m) rs<br>
&gt;&gt;  where f (Just n) = Just $ n + 1<br>
&gt;&gt;        f Nothing = Just 1<br>
&gt;&gt;        slot = findSlot n rs<br>
&gt;&gt;        findSlot x (r@(Range a b):rs)<br>
&gt;&gt;          | x &gt;= a &amp;&amp; x &lt; b = r<br>
&gt;&gt;          | otherwise       = findSlot x rs<br>
&gt;&gt;        findSlot x []       = OutOfBounds<br>
&gt;<br>
&gt; Try changing &quot;Just $ n + 1&quot; to &quot;Just $! n + 1&quot;.  It is possible that<br>
&gt; this change alone removes the leak (it is the only obvious leak I&#39;m<br>
&gt; seeing right now).<br>
&gt;<br>
&gt; Also, for findSlot you may want to do a binary search, but that isn&#39;t<br>
&gt; related to the leak at all.<br>
&gt;<br>
&gt; Cheers,<br>
&gt;<br>
&gt; --<br>
&gt; Felipe.<br>
&gt;<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>