-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Reduce minified code size to be closer to closure #2932
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
Comments
cc @chadaustin |
Hi @kripken |
I don't know offhand, but it should be almost all the time. Just any C code doing |
What's a good first step (or 2) to working on this? |
I would just emit code as minified but with whitespace ( |
|
#2801 is a concrete example of something that would help here. |
Regarding that, see #3523 |
Is this still relevant? |
I think we can close this. The asm.js minifier has been improved over time, and meanwhile anyhow our focus is shifting more to wasm. For the non-asm.js code that still matters in wasm, I don't think it makes sense to compete with closure, we should just use it. |
I did some quick tests to see why closure emits smaller minified code than us.
First main issue is we do not currently run uglify's squeeze optimizations (
return uglify.uglify.ast_squeeze(ast)
), which are supposed to be competitive with closure. This could reduce code quite a bit. It is great on small testcases, but infinite loops on larger ones. Perhaps upgrading our uglify would fix that, or we could investigate what's going on.We would only enable optimizations consistent with asm.js though. But most should be. I suppose another option is to do the same with closure, but that seems much harder.
I also looked at some source samples to see why closure is better. Some observations:
{ x; y; z; }
into(x, y, z)
. Often the parens can be dropped, and it enables more optimizations (see next).if (q) (x, y, z) [else (a, b, c)] => q ? (x, y, z) : [(a, b, c) or 0]
. This seems like a big optimization. It depends on the previous one. Note that this can casecade, so it needs to be done in a post-visitor.while(1) ==> for(;;)
, but need to measure perf.if (x) a = y else a = z
=>a = x ? y : z
x + (-y) => x - y
. Closure doesn't do that actually, but we should!x; for (;;)
=>for (x;;)
, saves one;
.The text was updated successfully, but these errors were encountered: