<p dir="auto">Hi guys,<br>
Thank you very much for all your work on babel, I believe front-end development wouldn't be where it is today without it.<br>
So, currently babel transpiles es2015 default parameters by making use of the <code class="notranslate"> arguments</code> variable, which has performance drawbacks.</p>
<h3 dir="auto">Input Code</h3>
<p dir="auto"><a href="https://babeljs.io/repl/#?babili=false&amp;evaluate=true&amp;lineWrap=false&amp;presets=es2015%2Ces2015-loose&amp;targets=&amp;browsers=&amp;builtIns=false&amp;debug=false&amp;code_lz=GYVwdgxgLglg9mABAQwCaoBTMQXkQBgBpEAjXRARgEpEBvAKEUQCcBTKEZpbAalIG56AX3pA" rel="nofollow">REPL</a> link available :)</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function add(a = 0, b = 1) {
  return a + b;
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-s1">a</span> <span class="pl-c1">+</span> <span class="pl-s1">b</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Babel Configuration (.babelrc, package.json, cli command)</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  presets: [
    [&quot;es2015&quot;, {&quot;loose&quot;: true}],
  ],
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-c1">presets</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">"es2015"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span><span class="pl-s">"loose"</span>: <span class="pl-c1">true</span><span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-kos">]</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

function add(aArg, bArg) {
  var a = aArg || 0;
  var b = bArg || 1;

  return a + b;
}"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s1">aArg</span><span class="pl-kos">,</span> <span class="pl-s1">bArg</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">aArg</span> <span class="pl-c1">||</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
  <span class="pl-k">var</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">bArg</span> <span class="pl-c1">||</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>

  <span class="pl-k">return</span> <span class="pl-s1">a</span> <span class="pl-c1">+</span> <span class="pl-s1">b</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Current Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

function add() {
  var a = arguments.length &gt; 0 &amp;&amp; arguments[0] !== undefined ? arguments[0] : 0;
  var b = arguments.length &gt; 1 &amp;&amp; arguments[1] !== undefined ? arguments[1] : 1;

  return a + b;
}"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-smi">arguments</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">!==</span> <span class="pl-c1">undefined</span> ? <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> : <span class="pl-c1">0</span><span class="pl-kos">;</span>
  <span class="pl-k">var</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-smi">arguments</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span> <span class="pl-c1">!==</span> <span class="pl-c1">undefined</span> ? <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span> : <span class="pl-c1">1</span><span class="pl-kos">;</span>

  <span class="pl-k">return</span> <span class="pl-s1">a</span> <span class="pl-c1">+</span> <span class="pl-s1">b</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto">Default parameters have historically been managed like in the "Expected behaviour" section, which is fast, I don't know much about ASTs in general so I'm not sure how trivial this is to change.<br>
I think there might be solutions that still make use of arguments, depending on what's easier to implement, but I'd avoid it if possible.<br>
<a href="https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments">This</a> is one, but I'm not sure of its perf impacts, so we'll have to test it.</p>
<h3 dir="auto">Context</h3>
<p dir="auto">I had been using babel's default parameters blindly and one of our functions ended up in "hot" code, which made me discover the perf problem and opening this issue.<br>
I know that <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/GoodBoyDigital/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/GoodBoyDigital">@GoodBoyDigital</a> and <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/bigtimebuddy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/bigtimebuddy">@bigtimebuddy</a> had to stop using them in some parts of PixiJs due to this problem, happy to hear your thoughts guys if you have anything to add from your perf tests.</p>
<h3 dir="auto">Your Environment</h3>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>6.25.0</td>
</tr>
<tr>
<td>node</td>
<td>v8.0.0</td>
</tr>
<tr>
<td>npm</td>
<td>5.0.4</td>
</tr>
<tr>
<td>Operating System</td>
<td>MacOSX 10.11.6</td>
</tr>
</tbody>
</table>
<p dir="auto">Thank you,<br>
Alvin</p>
<p dir="auto">Hi guys,<br>
Thank you very much for all your work on babel, I believe front-end development wouldn't be where it is today without it.<br>
So, currently babel transpiles es2015 default parameters by making use of the <code class="notranslate"> arguments</code> variable, which has performance drawbacks.</p>
<h3 dir="auto">Input Code</h3>
<p dir="auto"><a href="https://babeljs.io/repl/#?babili=false&amp;evaluate=true&amp;lineWrap=false&amp;presets=es2015%2Ces2015-loose&amp;targets=&amp;browsers=&amp;builtIns=false&amp;debug=false&amp;code_lz=GYVwdgxgLglg9mABAQwCaoBTMQXkQBgBpEAjXRARgEpEBvAKEUQCcBTKEZpbAalIG56AX3pA" rel="nofollow">REPL</a> link available :)</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function add(a = 0, b = 1) {
  return a + b;
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-s1">a</span> <span class="pl-c1">+</span> <span class="pl-s1">b</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Babel Configuration (.babelrc, package.json, cli command)</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  presets: [
    [&quot;es2015&quot;, {&quot;loose&quot;: true}],
  ],
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-c1">presets</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">"es2015"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span><span class="pl-s">"loose"</span>: <span class="pl-c1">true</span><span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-kos">]</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

function add(aArg, bArg) {
  var a = aArg || 0;
  var b = bArg || 1;

  return a + b;
}"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s1">aArg</span><span class="pl-kos">,</span> <span class="pl-s1">bArg</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">aArg</span> <span class="pl-c1">||</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
  <span class="pl-k">var</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">bArg</span> <span class="pl-c1">||</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>

  <span class="pl-k">return</span> <span class="pl-s1">a</span> <span class="pl-c1">+</span> <span class="pl-s1">b</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Current Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

function add() {
  var a = arguments.length &gt; 0 &amp;&amp; arguments[0] !== undefined ? arguments[0] : 0;
  var b = arguments.length &gt; 1 &amp;&amp; arguments[1] !== undefined ? arguments[1] : 1;

  return a + b;
}"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-smi">arguments</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">!==</span> <span class="pl-c1">undefined</span> ? <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> : <span class="pl-c1">0</span><span class="pl-kos">;</span>
  <span class="pl-k">var</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-smi">arguments</span><span class="pl-kos">.</span><span class="pl-c1">length</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span> <span class="pl-c1">!==</span> <span class="pl-c1">undefined</span> ? <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span> : <span class="pl-c1">1</span><span class="pl-kos">;</span>

  <span class="pl-k">return</span> <span class="pl-s1">a</span> <span class="pl-c1">+</span> <span class="pl-s1">b</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto">Default parameters have historically been managed like in the "Expected behaviour" section, which is fast, I don't know much about ASTs in general so I'm not sure how trivial this is to change.<br>
I think there might be solutions that still make use of arguments, depending on what's easier to implement, but I'd avoid it if possible.<br>
<a href="https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments">This</a> is one, but I'm not sure of its perf impacts, so we'll have to test it.</p>
<h3 dir="auto">Context</h3>
<p dir="auto">I had been using babel's default parameters blindly and one of our functions ended up in "hot" code, which made me discover the perf problem and opening this issue.<br>
I know that <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/GoodBoyDigital/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/GoodBoyDigital">@GoodBoyDigital</a> and <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/bigtimebuddy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/bigtimebuddy">@bigtimebuddy</a> had to stop using them in some parts of PixiJs due to this problem, happy to hear your thoughts guys if you have anything to add from your perf tests.</p>
<h3 dir="auto">Your Environment</h3>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>6.25.0</td>
</tr>
<tr>
<td>node</td>
<td>v8.0.0</td>
</tr>
<tr>
<td>npm</td>
<td>5.0.4</td>
</tr>
<tr>
<td>Operating System</td>
<td>MacOSX 10.11.6</td>
</tr>
</tbody>
</table>
<p dir="auto">Thank you,<br>
Alvin</p>