Skip to content

better instance Hashable IntSet? #269

Open
@jwaldmann

Description

I have an application that uses HashTable IntSet _ (see https://gitlab.imn.htwk-leipzig.de/waldmann/fdaln/-/blob/master/DFA.hs for benchmark - concluding that HashTable is a good choice, and actual use case https://gitlab.imn.htwk-leipzig.de/waldmann/presburger-arithmetic )

I find that it spends quite some time in Data.HashMap.Internal.hash, evaluating (what I assume to be inlined)

instance Hashable IntSet.IntSet where
    hashWithSalt salt x = IntSet.foldl' hashWithSalt
        (hashWithSalt salt (IntSet.size x))
        x

Can we do better here? If the IntSet is small, all the information is in (very few, often just one) Word64. The above implementation will unpack those - via Data.IntSet.Internals.fold'Bits which (I guess) is not fully inlined (it has a recursive go function. In theory, that could be unrolled, then fused ...)

Well, such an instance must then go into containers (not hashable) since it accesses the internal representation?

I may find some time (or a student) to work on this but I wanted to get some general comment and input first.

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