title: What is the overhead of Javascript async functions
body: <p><strong>The question</strong>: Is there, (and if yes, to what extent) a computational overhead in the engine runtime to declare a function as <code>async</code> and to eventually <code>await</code> as compared to a regular function's return statement ?</p>
  
  <pre><code>async function foo() {
      var x = await bar(); // &lt;--- bar() is non-blocking so await to get the return value
      return x; // the return value is wrapped in a Promise because of async
  }
  </code></pre>
  
  <p>Versus</p>
  
  <pre><code>function foo() {
      var x = bar(); // &lt;--- bar() is blocking inside its body so we get the return value
      return new Promise(resolve =&gt; { resolve(x); }); // return a Promise manually
  }
  </code></pre>
  
  <p><strong>Context</strong>:</p>
  
  <p>Due to the asynchronous direction taken by Javascript (and i.e. Nodejs), why did they not consider every function to be asynchronous (as per <code>async</code> keyword) by default ?</p>
  
  <p>This way, people could just decide to treat any function call as a <code>Promise</code> and play the asynchronous game, or just <code>await</code> what is necessary.</p>
  
  <p>I suppose that <code>await</code>-ing within a function body creates the overhead of stacking the local function's scope whereas the normal event loop proceeds when the function returns and does not have to push the inner function scope to the stack ?</p>
  
  <p>This comes down to a bonus question : in a complex hyerarchy of classes that (somewhere deep) requires one synchronous IO operation (see note) that would ideally be <code>await</code>'ed. It is only possible if that method is marked as <code>async</code>. Which in turn required the calling function to be <code>async</code> to be able to <code>await</code> it again and so forth. Thus, everything marked <code>async</code> and <code>await</code> when needed... How to deal with such a scenario ?</p>
  
  <p><strong>Note</strong>: Please do not argue about the necessity of not-doing any sync operations as this is not the point.</p>
  
  <p><strong>Note 2</strong>: This question is not about what is <code>await</code> or <code>async</code> nor when it executes. This question is about performance and the internals of the language (even though multiple implementations exist, there may be a inherent semantic overhead to the concept).</p>