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

Joachim Breitner mail at joachim-breitner.de
Wed Apr 30 11:41:15 UTC 2014


Am Dienstag, den 29.04.2014, 17:31 +0100 schrieb Niklas Hambüchen:
> This is just a short notice that using
>    foldl' (+) 0 [0..100000::Int]
> is over 10 times slower than using
>   flip execState 0 $
>     forLoop (0 :: Int) (< n) (+1) $ \i -> do
>       x <- get
>       put $! x + i
> with `loopFor` as on https://github.com/nh2/loop.

Did you look at the GHC Core generated? When starting to investigate
performance issues, reading Core simply is required – otherwise it’s
like search for a lost plain while refusing to look under the water

So can you compile your code with -ddump-simpl (and possibly flags
-dsuppress-uniques and -dsuppress-module-prefixes that make it more
readable) and compare the results: Any obvious differences, like
unboxing to Int# used in one place and not in the other?

If you need help deciphering core, paste the relevant bits in a mail to
this thread and we can help you.


Joachim “nomeata” Breitner
  mail at joachim-breitner.dehttp://www.joachim-breitner.de/
  Jabber: nomeata at joachim-breitner.de  • GPG-Key: 0xF0FBF51F
  Debian Developer: nomeata at debian.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140430/da157f1f/attachment.sig>

More information about the Haskell-Cafe mailing list