[Haskell-cafe] Analyzing slow performance of a Haskell program
bos at serpentine.com
Tue Aug 9 20:16:41 CEST 2011
On Tue, Aug 9, 2011 at 9:47 AM, Chris Yuen <kizzx2+haskell at gmail.com> wrote:
> - 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's a
> Windows problem.
No, GHC calls out to C for 64-bit integer ops on all 32-bit platforms.
> 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%
Actually, fromIntegral is usually a no-op, so chances are you're seeing the
effect of something else.
> - Changing `divMod` to `quotRem` saved another 20%
It's cheaper again to use quotInt# and remInt# as I did in my code.
> 1. Why are bangs needed on the length arrays?
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
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're all hoisted out and performed just once.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe