[Haskell-cafe] forLoop + strict State monad is much faster than foldl'

Patrick Wheeler patrick.john.wheeler at gmail.com
Thu May 1 14:00:57 UTC 2014


Int has a tight loop for `EnumFromTo`
http://git.haskell.org/packages/base.git/blob/HEAD:/GHC/Enum.lhs#l500

On the other hand look at `EnumFromTo` for word32
http://hackage.haskell.org/package/base-4.7.0.0/docs/src/GHC-Word.html#Word32

It calls `integralEnumFromTo`

Which is

 723<http://git.haskell.org/packages/base.git/blob/52c0b09036c36f1ed928663abb2f295fd36a88bb:/GHC/Real.lhs#l723>integralEnumFromTo
:: Integral a => a -> a -> [a]
 724<http://git.haskell.org/packages/base.git/blob/52c0b09036c36f1ed928663abb2f295fd36a88bb:/GHC/Real.lhs#l724>integralEnumFromTo
n m = map fromInteger [toInteger n .. toInteger m]

That is right you get converted to an Integer, then back again.

http://git.haskell.org/packages/base.git/blob/52c0b09036c36f1ed928663abb2f295fd36a88bb:/GHC/Real.lhs#l723

This seems to be the problem with all loops that use `Word32` and
`EnumFromTo`.

It looks like you could add a better `EnumFromTo` for `Word32` and you
would close the gap between the loops that are using `EnumFromTo` and those
that are not.

Patrick


On Tue, Apr 29, 2014 at 11:35 AM, Niklas Hambüchen <mail at nh2.me> wrote:

> Interestingly, the discrimination against Word32 does not end here:
>
> When compiling with -fllvm
> (
> http://htmlpreview.github.io/?https://github.com/nh2/loop/blob/master/results/bench-foldl-and-iorefs-are-slow-llvm.html
> ),
> we can see that the forLoop + strict State monad is completely compiled
> away to a no-op for Int, but not for Word32.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Patrick Wheeler
Patrick.John.Wheeler at gmail.com
Patrick.J.Wheeler at rice.edu
Patrick.Wheeler at colorado.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140501/cdc25d7e/attachment.html>


More information about the Haskell-Cafe mailing list