After converting some threads code to coroutines c...
# coroutines
j
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
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
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
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
@Sergey Bondari Care to share your finds?
s
That would be hard to share any code due to the internal compliance policy