<html><body>
<p>Hi all,<br>
<br>
<br>
<tt>&gt; &gt;&gt; So my theory now is:<br>
&gt; &gt;&gt; I do a large number of lookups.<br>
&gt; &gt; <br>
&gt; &gt; Try using Data.Array.Base.unsafeRead (and maybe <br>
&gt; &gt; ata.Array.Base.unsafeWrite). These avoid the bounds checking on the <br>
&gt; &gt; index each time you lookup something in the array.<br>
&gt; <br>
&gt; Right. &nbsp;Also keep an eye on the GC time (+RTS -sstderr) if you're using <br>
&gt; boxed mutable arrays - we don't do card-marking, so GC is pretty <br>
&gt; sub-optimal when it comes to large mutable boxed arrays. &nbsp;Decreasing the <br>
&gt; number of GCs with +RTS -A&lt;big&gt; can help if you're suffereing from this - <br>
&gt; but always try with and without, sometimes it makes things worse by making <br>
&gt; less effective use of the L2 cache.<br>
</tt><br>
<tt>Thanks for you advice.</tt><br>
<br>
<tt>I changed all the reads to unsafeReads and all the writes to unsafeWrites. That indeed sped up things a bit (about 10 percent on the total running time).</tt><br>
<br>
<tt>I also checked the GC time, but that is (only) 30% of the total running time.</tt><br>
<br>
<tt>So still, the program with ST array is about 3 times slower than the program with Data.Map.</tt><br>
<br>
<tt>Also, the function lookupEq that looks up the states of the equations from the array, is responsible for 20% of the running time, and 19% of the allocated memory. I would say that is should allocate almost no memory:</tt><br>
<br>
<tt>lookupEq :: Int -&gt; MyMonad (Maybe EquationState)</tt><br>
<tt>lookupEq cid =</tt><br>
<tt>&nbsp; do s &lt;- get</tt><br>
<tt>&nbsp; &nbsp; &nbsp;mEs &lt;- lift $ unsafeRead s cid</tt><br>
<tt>&nbsp; &nbsp; &nbsp;return mEs</tt><br>
<br>
<tt>type MyMonad a = forall s2. StateT (Eqns s2) (ST s2) a</tt><br>
<tt>type Eqns s2 = STArray s2 Int (Maybe EquationState)</tt><br>
<br>
data EquationState = EQS {cDefinition::Equation, usedBy::Map.Map Int (), ...}<br>
<br>
How can it be the lookupEq allocates memory? Is is not that, because of some tricky strictness/lazyness thing about ST array, unsafeRead causes the element that is read from the array to be copied in memory?<br>
<br>
Regards,<br>
Robert</body></html>