jack-pappas / ExtCore

An extended core library for F#.
Apache License 2.0
180 stars 32 forks source link

Add union function to HashMap #37

Closed 7sharp9 closed 6 years ago

7sharp9 commented 6 years ago

Pretty much the same as the Map.union function

jack-pappas commented 6 years ago

Thanks Dave! Would you mind adding a basic unit test or two for this function as well?

7sharp9 commented 6 years ago

@jack-pappas Yep, Ill add a few tests. Incidentally I was using this to try and improve on the map performance of some HM type inference with row polymorphism. Except it seems to be slower apart from high iteration counts vs map. Did you ever look into PersistantHashMap?

jack-pappas commented 6 years ago

PersistentHashMap as in the Scala or Clojure 'vector' type? I did look at it at one point but never got around to actually implementing it for ExtCore.

If you have an example / benchmark of some code where HashMap is slower than F# Map and you can post it somewhere, I'm happy to take a look. HashMap isn't guaranteed to be faster, but empirically I have found it to be faster in most cases I've used it.

7sharp9 commented 6 years ago

@jack-pappas Im implementing various HM type inference algorithms with extension like row and variant polymorphism, possibly rank n types as well. I found the 100,000 iterations was the time when map was outperformed by hashmap. To be honest I was using a string as a type var identifier where an int and rank would be more efficient. Even not got to the point where Im overly worried about performance yet, Im just very mindful of the generic comparison overhead on map, especially with a string as I was using, I was surprised hashmap was slower for lower iterations.