-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making Map.unorderedTraverse stack safe #4463
Conversation
The implementation calls the |
You can benchmark if you have time, but I bet the chain based will be faster. In the case of List for a small to medium list it was faster IIRC to not convert back and fourth from Vector and Chain. |
I noticed that the CI fails for native, I presume it's due to some stack size issue, not stack depth. |
I think they are worth running. Thanks! |
else | ||
G.map(Chain.traverseViaChain(fa.toIndexedSeq) { case (k, a) => | ||
G.map(f(a))((k, _)) | ||
}) { chain => chain.foldLeft(Map.empty[Int, B]) { case (m, (k, b)) => m.updated(k, b) } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think chain.iterator.toMap
would be more efficient potentially since it can use builder internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable, I'll use it for the bench!
I'll update you tomorrow, thanks 👋 |
There was no need to wait a night, the bench took ~45 minutes. These tests were done on a
These are the results:
They show that the unorderedTraverse that uses internally I'll use that implementation to fix the stack overflowing bug, as it could possibly solve the Scala Native issue in CI as I expect the Chain and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for doing this!
@armanbilge made me just notice that according to @djspiewak the M series is not great when it comes to bench marks: https://fosstodon.org/@SethTisue/110500223425754529 (if we don't find out noone we can try to run them in CI, but the machines are pretty crappy) |
I've managed to run these benchs on an These are the results:
The ratios are more or less the same, 8 times faster in one case, 13 in the other cc @armanbilge |
any news on this? |
I don't know the rules these days but went ahead and merged. It's been a while, I reviewed, there were great benchmarks, and in the worst case we can amend. Thank you! |
Fixes #4461.
The implementation is copied from
List.traverse_
.I added just simple tests for the Map implementation, that is the only one that changed.
I'm not sure where to add tests for other unorderedTraverse implementations, they're not worth a TestLaw class IMHO.