[Haskell-cafe] How to write fast for loops
mail at nh2.me
Tue Apr 29 00:35:29 UTC 2014
On 28/04/14 05:24, John Lato wrote:
> Doesn't that explain it? For Int, toEnum/fromEnum is a noop, but on
> Word32 it's not.
No, I'm not talking about the comparison between Word32 and Int:
I'm looking at Word32 only, "w32/loop vs w32/unsafeLoop" in the one
benchmark, and "loop vs unsafeLoop" in the other one.
That's the same functions over the same data type, just that the second
one iterates over more of that data type.
> Ahh, you made me look at the core again. I think this is related to
> your observation about V.enumFromTo being the same as V.fromList. With
> Word32 the generated core shows that this goes via a list representation
> instead of a nice loop. Which makes me suspect there's some RULE that
> applies to Stream.enumFromTo that is firing in the first case but not
> the second. And if I build both versions with -ddump-rule-firings,
> indeed I see that the Int version has
> Rule fired: enumFromTo<Int> [Stream]
> With nothing comparable for the Word32 version. I'd imagine if you grep
> for that in the Vector sources, you'd find something interesting.
I filed this as https://github.com/haskell/vector/issues/21.
Hopefully something comes out of it.
More information about the Haskell-Cafe