-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
enhance unused
#4858
enhance unused
#4858
Conversation
A one liner - well done! Handling the object literal self reference would be gravy. I haven't seen it in the wild. |
... except there's corner case to be fixed − will take a look after 💤 |
The third party application tests don't trigger a failure often, but are quite useful when they do. I think ufuzz is capable of creating property cycles in data structures. |
For every problem there is a solution that is simple, neat − and wrong. |
e1c84e1
to
2b45c76
Compare
As luck would have it, I know of a tool that can transform any JS into a one-liner. |
Do you have a reduced test case for the web-tooling-benchmark.sh failure? |
TBH I haven't even tried to reproduce the failure locally, since I've already figured out the logical fallacy before I woke up and rewrote the patch. So if the build testing fails again that's the first thing I'll do 👻 |
Been busy filtering through all the failure reports from GitHub up until recently. https://www.githubstatus.com/incidents/cj7gzzj30411 (Yeah, it lasted much longer than claimed, but they've been like that for a while now...) |
Hmm... what are you up to? https://github.com/mishoo/UglifyJS/runs/2404741773?check_suite_focus=true |
2b45c76
to
1725443
Compare
@alexlamsl Here's another optimization for you to consider... The alias
But if the code is altered slightly then the alias
If this optimization were to be implemented then the generated ES5 code at the end of this comment: !function() {
var e, t, r = {},
n = {};
t = n = function(e, t) {
return t.get ? t.get.call(e) : t.value
}, n.default = t, n.__esModule = true;
var u, a = n,
o = {};
u = o = function(e, t, r) {
if (!t.has(e)) throw new TypeError("attempted to " + r + " private field on non-instance");
return t.get(e)
}, o.default = u, o.__esModule = true;
var l = o;
e = r = function(e, t) {
var r = l(e, t, "get");
return a(e, r)
}, r.default = e, r.__esModule = true
}(); could be completely optimized away with After pass 1 the unneeded assignments I suspect that merge_vars may be at odds with this proposed optimization since it would complicate the analysis if the aliased single assigned variables are repurposed in the example above. Or perhaps not. |
Taught $ echo 'var x, y = x = Math.random(); console.log(x/y, y/x, (x+y)/x);' | uglify-js -bc toplevel
var x;
x = Math.random();
console.log(x / x, x / x, (x + x) / x); But that still leave your larger example with: $ uglify-js test.js -bc merge_vars=false,passes=9
!function() {
function n(e, t) {
return t.get ? t.get.call(e) : t.value;
}
function o(e, t, r) {
if (!t.has(e)) throw new TypeError("attempted to " + r + " private field on non-instance");
return t.get(e);
}
(n.default = n).__esModule = !0;
var a = n;
(o.default = o).__esModule = !0;
var r, l = o;
((r = function(e, t) {
var r = l(e, t, "get");
return a(e, r);
}).default = r).__esModule = !0;
}(); |
The impasse appears to be the remaining aliases
Some optimizations prevent other optimizations from occurring. It is a difficult balancing act. It wouldn't help in this case, but there might be heuristics that could be employed such as: If passes > 1 then As far as alias dropping goes, if one variable mirrors another and neither have subsequent assignments then the original variable could be used for the alias. No doubt there will be complications in practise. The devil is in the details. |
My plan is just to identify those and generalise the impeded option, e.g.
Thanks for the analysis − will take a closer look when I re-emerge from my alcove... |
This seems to be an obstacle to further optimization... Compare this code:
to:
|
@kzc this addresses the first two cases in #4855 (comment)
That last one is trickier since it relies on
join_vars
:which obviously won't work with self references.
I think to make that case work would require extending
reduce_vars
to cover object mutation in a similar manner to constant /class
/function