Issue 1:
Hi guys,

Thank you very much for all your work on babel, I believe front-end development wouldn't be where it is today without it.

So, currently babel transpiles es2015 default parameters by making use of the arguments variable, which has performance drawbacks.

Input Code

REPL link available :)

function add(a = 0, b = 1) {
return a + b;
}

Babel Configuration (.babelrc, package.json, cli command)

{
presets: [
["es2015", {"loose": true}],
],
}

Expected Behavior

"use strict";

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

return a + b;
}

Current Behavior

"use strict";

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

return a + b;
}

Possible Solution

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.

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.

This is one, but I'm not sure of its perf impacts, so we'll have to test it.

Context

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.

I know that @GoodBoyDigital and @bigtimebuddy 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.

Your Environment

software
version(s)

Babel
6.25.0

node
v8.0.0

npm
5.0.4

Operating System
MacOSX 10.11.6

Thank you,

Alvin

Issue 2:
Hi guys,

Thank you very much for all your work on babel, I believe front-end development wouldn't be where it is today without it.

So, currently babel transpiles es2015 default parameters by making use of the arguments variable, which has performance drawbacks.

Input Code

REPL link available :)

function add(a = 0, b = 1) {
return a + b;
}

Babel Configuration (.babelrc, package.json, cli command)

{
presets: [
["es2015", {"loose": true}],
],
}

Expected Behavior

"use strict";

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

return a + b;
}

Current Behavior

"use strict";

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

return a + b;
}

Possible Solution

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.

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.

This is one, but I'm not sure of its perf impacts, so we'll have to test it.

Context

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.

I know that @GoodBoyDigital and @bigtimebuddy 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.

Your Environment

software
version(s)

Babel
6.25.0

node
v8.0.0

npm
5.0.4

Operating System
MacOSX 10.11.6

Thank you,

Alvin