Use Set.alterF in nubOrd#1228
Conversation
sjakobi
left a comment
There was a problem hiding this comment.
I think it's very good to reduce the number of Ord comparisons, but it would be better to if the new implementation didn't allocate all these Maybes.
|
Ah but it doesn't, the |
Compared to the previous implementation of `member` followed by `insert`, `alterF` uses `memberIndex` and `insertAt`. This avoids all the element comparisons in `insert`, at the cost of `memberIndex` being a little more expensive than `member`. I expect this change to be an improvement in typical use cases.
Ah, I missed that! And it appears that you managed to reduce the allocations in #1229! 👍 |
Compared to the previous implementation of
memberfollowed byinsert,alterFusesmemberIndexandinsertAt. This avoids all the element comparisons ininsert, at the cost ofmemberIndexbeing a little more expensive thanmember. I expect this change to be an improvement in typical use cases.Related: #1205
Benchmarks with GHC 9.14: