<blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex" class="gmail_quote">It&#39;s cheaper again to use quotInt# and remInt# as I did in my code.<br></blockquote><div>
<br>Just want to point out that this is actually surprisingly less of an impact than I thought. As I did the step-by-step break down (you can see my blog post), this one (changing `quotRem` to `quotInt#` and `remInt#`) yielded almost negligible differences. Every other change had more impact than this, including turning the `Data.Array.Unboxed` into &quot;lookup functions&quot; (like `lenOnes 0 = 0; lenOnes 1 = 3; lenOnes 2 = 3; ...`)<br>


</div><div><br>Chris <br></div><br><div class="gmail_quote">On Wed, Aug 10, 2011 at 2:16 AM, Bryan O&#39;Sullivan <span dir="ltr">&lt;<a href="mailto:bos@serpentine.com" target="_blank">bos@serpentine.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div>On Tue, Aug 9, 2011 at 9:47 AM, Chris Yuen <span dir="ltr">&lt;<a href="mailto:kizzx2%2Bhaskell@gmail.com" target="_blank">kizzx2+haskell@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<br>- I was using GHC 32-bit. Int is 32-bit there, so I needed Int64. It turns out 64-bit operations in 32-bit programs are just darn slow. Maybe it&#39;s a Windows problem.</blockquote><div><br></div></div><div>No, GHC calls out to C for 64-bit integer ops on all 32-bit platforms.</div>


<div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> On Linux 64 bit GHC Int is 64 bit so everything just works. Changing Int64 to Int liberates me from many `fromIntegral` which saved 20%<br>



</blockquote><div><br></div></div><div>Actually, fromIntegral is usually a no-op, so chances are you&#39;re seeing the effect of something else.</div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





- Changing `divMod` to `quotRem` saved another 20%<br></blockquote><div><br></div></div><div>It&#39;s cheaper again to use quotInt# and remInt# as I did in my code.</div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



1. Why are bangs needed on the length arrays?</blockquote><div><br></div></div><div>GHC has to deconstruct the Vector in order to get at the real underlying array, so that unsafeIndex can perform the actual index into the real underlying array.</div>



<div><br></div><div>Without bang patterns, the code performs at least one deconstruction on every iteration through the loop. Each deconstruction has a cost. With the bang patterns, they&#39;re all hoisted out and performed just once.</div>



</div>
</blockquote></div><br>