-
|
While the new Raise DSL seems neat, I'm wondering what possible performance impact it might actually have. Given that the return type of To drive the point home, consider two possible implementations of a simple function responsible for making sure a number is positive: For the sake of the argument, imagine this function is a part of some application's critical path (e.g. a tight, performance-critical loop). Would the second implementation be expected to have a significantly negative impact on performance? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hey @404-, Thank you for your interest, and this is actually a great question! It's not explicitly mentioned anywhere in the documentation, but perhaps it should! So Kotlin(X) Coroutines requires However there is no performance impact, since stacktrace creation is disabled. So the performance impact you're referring to comes from stacktrace creation, which occurs on construction of any subclass of KotlinX Coroutines disables stacktrace creation for For reference, Arrow, KotlinX Coroutines. We replaced the |
Beta Was this translation helpful? Give feedback.
Hey @404-,
Thank you for your interest, and this is actually a great question!
It's not explicitly mentioned anywhere in the documentation, but perhaps it should! So Kotlin(X) Coroutines requires
CancellationExceptionto cancel a running coroutine, so forraiseto properly work in the Kotlin ecosystem we're required to useCancellationException. (There are other implementation possible forRaisewithout using exceptions, but they don't cooperate nicely with other Coroutine code).However there is no performance impact, since stacktrace creation is disabled. So the performance impact you're referring to comes from stacktrace creation, which occurs on construction of any subclass of
Throwable…