Hey, quick question, I was wondering about the cos...
# coroutines
r
Hey, quick question, I was wondering about the cost of creating a
coroutineScope
that ends up doing nothing. For example should I bother writing:
Copy code
if (collection.isNotEmpty()) {
  coroutineScope {
    collection.forEach { item -> launch { doSomeComplexSuspendingWork(item) } }
  }
}
Or does it not really matter much and this would be just as efficient (and cleaner to read)
Copy code
coroutineScope {
  collection.forEach { item -> launch { doSomeComplexSuspendingWork(item) } }
}
o
probably pre mature optimization, it could be an issue, but unlikely for most cases
l
Depends on if that code path is executed frequently or not. If it's once per app installation, don't bother. If it's quite often, the optimization might add up.
Or subtract down I should say.