Skip to content

V.enumFromTo is only fast for Int, not Word32 #21

@nh2

Description

@nh2

In https://groups.google.com/d/msg/haskell-cafe/Ms4sKZBwTtw/55CFywSytBQJ I benchmark different alternatives to forM_ [1..n] to each other.

When looking at V.forM_ (V.enumFromTo 1 n), we noticed that this gets only optimised away to a fast loop when using Vector Int. With Vector Word32, it's 5 times slower.

What @JohnLato thinks about this:

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 [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.

It would be great if somebody familiar with the vector library could check out whether there are indeed RULES missing for types like Word32.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions