-
Notifications
You must be signed in to change notification settings - Fork 31
Faster & simpler traverse for StrMap #96
Conversation
This looks very encouraging, but I'm not overly keen on having a copy of the old implementation in the tests to test against. Do we not already have some code testing that |
Sounds reasonable. I added some more straightforward tests of Traverse. Technical tangent: Since the entries in a
Just throwing that out there, as a disclaimer and in case you have any thoughts on it. Thanks a bunch! |
Not-at-all-urgent ping on this, @hdgarrood. (Thanks!) |
This looks sensible to me but I am not sure why the current instance was written that way, and I'd like to get input from someone who does before approving this. Also just wondering re your tangent: the current
Presumably this depends on insertion order? Can you construct such a pair? |
Sounds wise. The traverse instance for StrMap dates from 1463e59. @joneshf, can you see this pull request? Do you see anything wrong about replacing traverse f ms = foldr (\x acc -> union <$> x <*> acc) (pure empty) ((map (uncurry singleton)) <$> (traverse f <$> toArray ms)) with traverse f ms = fold (\acc k v -> insert k <$> f v <*> acc) (pure empty) ms ?
Yup!
Here is an example with the old |
Actually I've just realised - won't the new version still be quadratic, since each |
Good point. I suppose it depends on use-case. If you are The situation that motivated me was more similar to If you think the first situation is important to protect, then I might back off on my approach, since I probably want to add further optimizations which move away from use of a generic |
I would imagine that converting |
Ohh, I see, you would need to do It's just occurred to me that I have never wanted to use this instance, so I really don't have any strong opinions here. This PR does seem to be an improvement over the current code in any case so I'd be happy to see it merged now, and then we can revisit these issues later. |
@hdgarrood Let's merge this if you're happy with the trade-offs. Thanks for reviewing! Thanks @joshuahhh! |
Yes, thank you! |
Please take a look!
Here's some benchmarking (code):