title: Kotlin suspend function recursive call
body: <p>Suddenly discover that recursive call of suspend function takes more time then calling the same function but without <code>suspend</code> modifier, so please consider the code snippet below (basic Fibonacci series calculation):</p>
  
  <pre><code>suspend fun asyncFibonacci(n: Int): Long = when {
      n &lt;= -2 -&gt; asyncFibonacci(n + 2) - asyncFibonacci(n + 1)
      n == -1 -&gt; 1
      n == 0 -&gt; 0
      n == 1 -&gt; 1
      n &gt;= 2 -&gt; asyncFibonacci(n - 1) + asyncFibonacci(n - 2)
      else -&gt; throw IllegalArgumentException()
  }
  </code></pre>
  
  <p>If I call this function and measure its execution time with code below: </p>
  
  <pre><code>fun main(args: Array&lt;String&gt;) {
      val totalElapsedTime = measureTimeMillis {
          val nFibonacci = 40
  
          val deferredFirstResult: Deferred&lt;Long&gt; = async {
              asyncProfile("fibonacci") { asyncFibonacci(nFibonacci) } as Long
          }
          val deferredSecondResult: Deferred&lt;Long&gt; = async {
              asyncProfile("fibonacci") { asyncFibonacci(nFibonacci) } as Long
          }
  
          val firstResult: Long = runBlocking { deferredFirstResult.await() }
          val secondResult: Long = runBlocking { deferredSecondResult.await() }
          val superSum = secondResult + firstResult
          println("${thread()} - Sum of two $nFibonacci'th fibonacci numbers: $superSum")
      }
      println("${thread()} - Total elapsed time: $totalElapsedTime millis")
  }
  </code></pre>
  
  <p>I observe further results:</p>
  
  <pre><code>commonPool-worker-2:fibonacci - Start calculation...
  commonPool-worker-1:fibonacci - Start calculation...
  commonPool-worker-2:fibonacci - Finish calculation...
  commonPool-worker-2:fibonacci - Elapsed time: 7704 millis
  commonPool-worker-1:fibonacci - Finish calculation...
  commonPool-worker-1:fibonacci - Elapsed time: 7741 millis
  main - Sum of two 40'th fibonacci numbers: 204668310
  main - Total elapsed time: 7816 millis
  </code></pre>
  
  <p>But if I remove <code>suspend</code> modifier from <code>asyncFibonacci</code> function, I'll have this result:</p>
  
  <pre><code>commonPool-worker-2:fibonacci - Start calculation...
  commonPool-worker-1:fibonacci - Start calculation...
  commonPool-worker-1:fibonacci - Finish calculation...
  commonPool-worker-1:fibonacci - Elapsed time: 1179 millis
  commonPool-worker-2:fibonacci - Finish calculation...
  commonPool-worker-2:fibonacci - Elapsed time: 1201 millis
  main - Sum of two 40'th fibonacci numbers: 204668310
  main - Total elapsed time: 1250 millis
  </code></pre>
  
  <p>I know that's better to rewrite such a function with <code>tailrec</code> it will increase its execution time apx. almost in 100 times, but anyway, what this <code>suspend</code> key word does that decrease execution speed from 1 second to 8 seconds?</p>
  
  <p>Is it totally stupid idea to mark recursive functions with <code>suspend</code>?</p>