Skip to content

[RFC Needed] Allow creation of Map using custom comparer #1770

@mrange

Description

@mrange

Map is suprisingly slow. I have experimented a bit and it seems to boil down to the generic comparer used by Map.

I have experimented with adding a method to Map that allows me to specify a custom comparer:

      let comparer = 
        { new IComparer<Key> with
          member x.Compare (l, r) = l.Value.CompareTo r.Value
        }
      Map.emptyWithComparer comparer

and ran some performance tests. These are the numbers for the generic comparer:

Running test case: Map     - Lookup......It took 8686 ms, CC=0, 0, 0
Running test case: Map     - Insert......It took 9838 ms, CC=458, 0, 0
Running test case: Map     - Remove......It took 7388 ms, CC=387, 0, 0

These are the numbers with comparer above.

Running test case: Map     - Lookup......It took 347 ms, CC=0, 0, 0
Running test case: Map     - Insert......It took 1897 ms, CC=458, 0, 0
Running test case: Map     - Remove......It took 1342 ms, CC=387, 0, 0

So it do seem the comparer affect performance and it could be beneficial for performance sensitive applications to be able to provide a customer comparer.

Now; is this something that would be worth creating a PR for or are there reasons why this is not desired?

Regards,

Mårten

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions