I'm wondering if there's general recommendation / ...
# coroutines
t
I'm wondering if there's general recommendation / way to measure coroutine context switch cost to make code decision, or if in the global picture (For Android apps in my case on potentially low end devices) the cost are not important enough to base decisions on this as the coroutine engine will always optimize better than doing it manually. A a simple example imagine you have a blocking network call to make and then a multicast lock to release.
Copy code
launch {
   withContext(IO) { blockingCall() }
   lock.release()
}
This can trigger a switch and one may want to optimize to:
Copy code
launch(IO) {
  blockingCall()
  lock.release()
}
Is there any interest to do that? Or is it better to keep clear separation between blocking calls on IO and non blocking calls?
t
it's depends on caller situation because withContext() have some fast path that selected by condition. please read implementation of it.