-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
More optimizations #25
Comments
Removing unused arguments is an unsafe optimisation as it will effect runtime behaviour as |
Yep. This is one of those almost-safe optimizations which will "work" most of the time but could silently bite you. We'll need to have it as part of the advanced/unsafe category. This is also somewhat similar to In practice, I'm seeing tons of stuff like |
Maybe have it as an option. FWIW GCC does this by default. On Wed, Jun 1, 2016 at 5:39 PM Juriy Zaytsev notifications@github.com
|
Edit 1: added more
|
Wow, closure is really nailing it, huh... |
I wanted to expand on that first "Resolve identity/simple functions" for CC since it does it quite nicely:
|
re: Use arrow functions (in ES6 browsers) How should babel-minify handle minifying using modern language features that are normally compiled down to ES5 by Babel? |
We can't turn function functions into arrow functions. It's an unsafe optimisation. Arrow functions have no |
James: I don't think that's necessary because you can always add the On Wed, Jul 6, 2016, 2:26 PM Sebastian McKenzie notifications@github.com
|
Yes, but there are places where ES5 code could be optimized more by using ES6+ features. I'm sure there are cases where we'd find arrow functions acceptable to use. Should optimizations like that be inferred? configured? |
Ideally the user would either be able to enable/disable each transform or use @kittens then maybe the function-to-arrow transform could only apply to functions that are verified to never user the prototype. |
It may be early for this, but should Like: https://github.com/postcss/postcss-plugin-suggestion-box and https://github.com/sindresorhus/module-requests Perhaps babel itself could benefit from one |
A few more optimizations for conditionals -
|
For the 1st case, I guess we would need to "fold" all the same-named methods as long as they're the only ones present in blocks and are in the same order? if (x) { foo(a); bar(y); } else { foo(b); bar(z); }
// becomes
foo(x ? a : b);
bar(x ? y : z); but these won't work: if (x) { bar(y); foo(a); } else { foo(b); bar(z); }
if (x) { foo(a); } else { foo(b); bar(z); } |
May be |
@napa3um Already suggested near the end of #25 (comment) @hzoo Would it make sense to open a repo for the suggestions as suggested earlier? Or maybe just one-enhancement-per-issue so they can be easily discussed and tracked. |
Came across this one, too: https://github.com/nolanlawson/optimize-js |
We should also turn |
So strange, I could swear it wasn't happening for me in repl. |
|
I'd like to see unnecessary, single-use variables get inlined and also functions like this: (function ([, a, b]) {
return (function (c, d) {
return c + d;
})(a, b);
})(thing);
(function ([, a, b]) {
var e = (function (c, d) {
return c + d;
})(a, b);
return e;
})(thing);
(function ([, a, b]) {
(function (c, d) {
log(c + d);
})(a, b);
})(thing);
var a = b.something();
run(a.other());
// become
(function ([, c, d]) {
return c + d;
})(thing);
(function ([, c, d]) {
return c + d;
})(thing);
(function ([, c, d]) {
log(c + d);
})(thing);
run(b.something().other()) |
That'd be great! Anything that isn't used more than once should be inlined. I often declare variables for readability but I could just as well write one-liners instead. |
These are shorter: [1].indexOf(1)!==-1; // contains
(ideal)
[1].includes(1); [1].indexOf(1)===-1; // doesn't contain
(ideal)
![1].includes(1)
For property access: var a = foo.bar;a = foo;
(all) var a=foo.bar;a=foo;
(ideal) foo.bar;var a=foo; Also, a couple other thoughts:
if (foo === undefined) {
return undefined
}
// becomes
var _babiliUndefined
if (foo === _babiliUndefined) {
return _babiliUndefined
}
// after mangling
var a
if (b === a) {
return a
} Some of the things presented in https://codegolf.stackexchange.com/q/2682/44689:
|
Coming from #591, where @loganfsmyth suggested (after some discussion) that babel-minify place a It should be possible to either put the {
let _void0
// code here
} This would increase code size if |
Replace |
bar
infunction foo(bar) { }
)return
when possible (e.g.return [1,2,3]
→return[1,2,3]
)var result = expression(); foo.bar = result;
→foo.bar = expression()
The text was updated successfully, but these errors were encountered: