-
Notifications
You must be signed in to change notification settings - Fork 1.2k
No outlining? / counterproductive inlining? #3203
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
Created Google internal issue http://b/123244691 |
re 1: No, Closure doesn't currently 'outline' functions. In this case I'm not sure that would be something we want to do: Closure prefers to optimize for post-gzip size, even when that means pre-gzip size is larger. And gzip (and other compression tools) are generally good at handling long repeated strings. The gzipped size of the Closure example is less than the handwritten example (95 bytes vs. 106 bytes) re 2: As with your original question, I'd expect inlining If you're interested, there's another rarely-used Closure option to alias long strings in the code to short variables. This is not on by default inside Google, as most of the time gzip does a better job with the strings, but a few projects have found it helps them: |
Coming back to this after a while.. How do I enable the AliasStrings pass? I tried looking at the documentation at https://github.com/google/closure-compiler/wiki/Flags-and-Options , searching for "pass" or "alias", but was unsure how to enable it. I agree that outlining automatically is probably not a smart thing to do. In my case, using a I do not place much value to estimating post-gzip sizes, since that is dangerous to do especially on these kind of tiny examples. Even if a really small example compresses slightly better, there is no guarantee that in a large page it would behave the same. (the only cases I care about post-gzip sizes are when there is an "entropy proof" that can be applied to the reasoning, e.g. "always use single-quotes and not a mix of single and double quotes", and so on) |
Optimizing Emscripten WebGL support library in emscripten-core/emscripten#13732 today, and still affected by this issue. In today's scenario, I have function getLeftBracePos(name) {
return name.slice(-1) == ']' && name.lastIndexOf('[');
}
...
var leftBrace = getLeftBracePos(nm);
...
leftBrace = getLeftBracePos(name); where Closure wants to inline Explicitly passing |
Uh oh!
There was an error while loading. Please reload this page.
Consider
A:
this minifies down to
1:
which is 113 bytes. Beautified to be more readable:
the extern browser API function
requestAnimationFrame
is sufficiently long, that it would be beneficial to outline access to that function. That is, one can hand-write the following equivalent minified code:2:
which is 112 bytes, winning by one character. Beautified for better readability:
I.e. if access to
requestAnimationFrame()
is outlined to a function of its own that is minified, then it can be accessed via a minified name to net a size saving. Here the saving is only one byte, but if across the whole program there were more accesses torequestAnimationFrame()
, the saving would be more considerable.Of course there is an extra function call indirection, which might mean lower performance, so not sure if this is something that would always be better, but perhaps a tradeoff call. However, if I manually outline, i.e. had hand-written the following JS code to start with:
B:
then it seems like an incorrect call for Closure to inline function
raf
, because the resulting program will be bigger by one character than the version whereraf
was not inlined. So in this case, one might expect to get version 2 instead of 1 to retain the small size? However the above code does generate 1, instead of 2.The above raises two questions to mind:
The text was updated successfully, but these errors were encountered: