Deprecate parTraverseN/parSequenceN with semaphore limit as Long #331
Deprecate parTraverseN/parSequenceN with semaphore limit as Long #331
Conversation
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.
Couple of small nits. Great catch @satyamagarwal! Thanks for keeping such a close eye on this!! 👏 👏 👏
arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/ParTraverse.kt
Outdated
Show resolved
Hide resolved
arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/ParTraverse.kt
Outdated
Show resolved
Hide resolved
arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/ParTraverse.kt
Outdated
Show resolved
Hide resolved
I don't know what previous build integration does, but it is failing everytime it runs. |
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.
Not sure how the build step managed to pass. The integration steps builds this project together with master
of Arrow Core
There was a mistake in the tests, I tested this locally with the following stress test.
I also saw that we can add inline
to the parTraverse.kt
implementations, it requires the lambdas to be defined as crossinline f: suspend () -> A
to work properly.
checkAll(5000, Arb.constant(Unit)) { _ ->
val ref = Atomic(0)
(0 until 10_000)
.map { suspend { ref.update { it + 1 } } }
.parSequenceN(5)
ref.get() shouldBe 10_00
}
Thanks again for the contribution @satyamagarwal! 👏 👏
arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ParTraverseTest.kt
Outdated
Show resolved
Hide resolved
arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ParTraverseTest.kt
Outdated
Show resolved
Hide resolved
this test doesn't finish on my machine. |
This should probably be a new PR right ? I can find time do it in a few days. |
@satyamagarwal a new PR for that is fine! Doesn't need to be in this one 👍 |
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.
That stress test runs fine on my machine 🤔 It takes quite some time tho since it's launching 10_000
coroutines 5000 times, and it's doing so by limiting the parallelism to 5
. 😀
arrow-fx-coroutines/src/test/kotlin/arrow/fx/coroutines/ParTraverseTest.kt
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
"parSequenceN can traverse effect full computations" { |
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.
this finally completed in 32 minutes. :D
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.
Oh we probably don't want to push that test to CI 😅 I just linked it because that's what I tried locally before I realized we were using i
from IntRange
instead of from update
.
It passed in 2-3 minutes locally for me.
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.
okay. I'll revert it :)
0fa1172
to
e0f85f5
Compare
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.
Looks perfect! 👏 👏 Thank you so much for taking care of this @satyamagarwal
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 @satyamagarwal !
Issue
324
Status
READY
Description
The current apis parTraverseN and parSequenceN use semaphore limit as
Long
type, and convert toInt
which can lead to overflow issue.This pr deprecates these methods, sets a validation check to fail the api if limit is more than
Int
range, and introduces new apis that takes limit asInt
type.Todos
Deploy Notes
Would like help on if I need to do something about deploying @nomisRev
Related PRs