title: Which of coroutines (goroutines and kotlin coroutines) are faster?
body: <p>Kotlin corutines is sugar for finite state machine and some task runner (for example, default ForkJoinPool). <a href="https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#implementation-details" rel="noreferrer">https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#implementation-details</a> </p>
  
  <p>In other words, there is no runtime coroutines in java/kotlin runtime yet (but this can change with <a href="http://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.html" rel="noreferrer">http://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.html</a> ). Kotlin coroutine is just sequential of tasks, which are executed one by one. Each task can be executed in any thread from thread pool.</p>
  
  <p>Go runtime supports "coroutines". But goroutines is not the real coroutines. Goroutines does not allow to set yield points in program. Also, Go does not allow to set custom thread pool. You can to set only size of threads in default pool. </p>
  
  <p>First difference between kotlin coroutines and goroutines is Go runtime manages which coroutine is running at this moment. When goroutine are blocked at some IO operation (or synchronization primitives), Go choices next Job to execute it. In JVM there is no intellectual job switching in such terms. </p>
  
  <p>Because of this, Go can cheaply change currently running job. Go has only to change few registries <a href="https://groups.google.com/forum/#!msg/golang-nuts/j51G7ieoKh4/wxNaKkFEfvcJ" rel="noreferrer"><a href="https://groups.google.com/forum/#!msg/golang-nuts/j51G7ieoKh4/wxNaKkFEfvcJ" rel="noreferrer">https://groups.google.com/forum/#!msg/golang-nuts/j51G7ieoKh4/wxNaKkFEfvcJ</a></a>. But some people say, that JVM can use stack of threads instead of using registers. So there is no saving and loading of registers at all.</p>
  
  <p>The second difference between kotlin coroutines and goroutines is type of coroutines. Kotlin coroutines is stackless coroutines. Goroutines are stackful coroutines. All state of Kotlin coroutines are stored in Kotlin context, which is stored in heap. Goroutines state is stored in registers and thread stack.</p>
  
  <p>I want to know, which coroutines (goroutines and kotlin coroutines) are faster in IO bound tasks? CPU bound tasks? What about memory consumption?</p>