https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

Tolriq

11/09/2018, 4:23 PM
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

tateisu

11/10/2018, 6:17 AM
it's depends on caller situation because withContext() have some fast path that selected by condition. please read implementation of it.
7 Views