[feature-request][discussion][babel-plugin-transform-es2015-parameters] decrease byte size of transformed function (T6892)
Author: babel-botCreated Dec 27, 2015Updated Sep 2, 2026
Labelsarea: perfhelp wanted
Issue originally made by @fabiomcosta
Description
The current rest transformation adds a bunch of code to the function in order to avoid the function body to get deoptimized by V8.
function foo(a, ...bar) {
}
// is transformed to:
function foo(a) {
for (var _len1 = arguments.length, bar = Array(_len1 > 1 ? _len1 - 1 : 0), _key1 = 1; _key1 < _len1; _key1++) {
bar[_key1 - s] = arguments[_key1];
}
}But since arguments used as the second parameter of the apply function doesn't deoptimizes a function body, we could change that to
function sliceArguments() {
for (var s = this, _len1 = arguments.length, args = Array(_len1 > s ? _len1 - s : 0), _key1 = s; _key1 < _len1; _key1++) {
args[_key1 - s] = arguments[_key1];
}
return args;
}
function foo(a) {
var bar = sliceArguments.apply(1, arguments);
}On multiple instances of functions using rest params this could greatly decrease the byte size. Let me know what you guys think.
Source: babel/babel