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

Jakub Aniola

04/23/2019, 10:36 AM
After converting some threads code to coroutines code, my benchmarks showed that memory consumption decreases but execution time is much longer with coroutines. I watched some talks and read multiple articles says that coroutines are “very light-weight threads”. So I see that gives me a better results with memory, but is it possible that conversion causes execution time increase? Or its just may be my wrong way of implementing them
r

ribesg

04/23/2019, 10:51 AM
Starting a new coroutine is basically free while starting a new thread costs a lot, so you basically have a problem. You’re probably running all your coroutines on a single thread
s

sitepodmatt

04/23/2019, 11:17 AM
You can print the thread id to help you determine... if you started with runblocking and then have launch's/async's and even nested of.. then they all going to inherit the dispatcher from runblocking which iirc reuses the thread it was start on turning it into kind of an event loop
s

Sergey Bondari

04/23/2019, 5:23 PM
I’ve got about 25% in execution time improvement when switching from Rx with okhttp, to coroutines and apache http async client on a network heavy application
s

Sam

04/23/2019, 6:03 PM
@Sergey Bondari Care to share your finds?
s

Sergey Bondari

04/23/2019, 6:06 PM
That would be hard to share any code due to the internal compliance policy
5 Views