-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature-request][discussion][babel-plugin-transform-es2015-parameters] decrease byte size of transformed function (T6892) #3927
Comments
Looks like it could be a helper yeah! |
As far as I understand it, passing |
Maybe @bmeurer could shed some light on this one? Is it worth to implement such helper to reduce bundle sizes? |
Some research yields: d3/d3-selection#111 Node has specifically avoided using |
It's definitely fine by now because it no longer disables optimization for that function (which BTW is not the same as deoptimization), but the helper approach will likely be slower. |
Some of these optimizations were targeted for the old V8 infrastructure, with Crankshaft. @bmeurer, on Turbofan, would the following implementation disable optimizations for the function foo(a) {
var bar = Array.prototype.slice.call(arguments, 1);
} The main improvement/suggestion from this issue is to decrease the amount of code when we have multiple functions using variable arguments ( |
I don't think the issue there would be disabling optimizations but rather that manually copying is faster than slice, especially for a small number of arguments. (I know that doesn't apply to the latest V8 but Babel obviously would have to worry about quite a few versions back.) With latest node, for example, it's about 2.4x faster to use the in place copying of arguments than |
TurboFan doesn't disable optimization for anything, except when your function is way too big (really, really huge), or when it runs out of virtual registers/stack slots while trying to compile the function (unlikely). @apapirovski is right, it's about the performance penalty that you still incur with current versions in Node. |
Sounds like a helper function like this is what we are looking for then: function sliceArgumentsBy(by, _args) {
for (var s = by, _len1 = _args.length, args = Array(_len1 > s ? _len1 - s : 0), _key1 = s; _key1 < _len1; _key1++) {
args[_key1 - s] = _args[_key1];
}
return args;
}
function foo(a) {
var bar = sliceArgumentsBy(1, arguments);
} |
Since the whole point of transpilation is to find common ground where all browsers can execute the code, it doesn't seem like a good idea to use something that causes issues on older versions of V8 (and presumably it might do the same for other engines). It's not like we're talking just about babel's runtime here where the version of V8 is more controlled. If a helper is desired then using it with |
@apapirovski correct, slower on runtime, but the transpiled code will end up having less bytes, which will make the final code load faster. Thanks for all the input so far folks! |
This helper is likely going to disable optimization on older versions of V8 (before TurboFan), since the |
@bmeurer then I guess we could use the one I suggested initially on the issue. |
|
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.
But since arguments used as the second parameter of the
apply
function doesn't deoptimizes a function body, we could change that toOn multiple instances of functions using rest params this could greatly decrease the byte size.
Let me know what you guys think.
The text was updated successfully, but these errors were encountered: