-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Redundant unary '+' operators not merged #504
Comments
I'm happy to work on a patch if someone wouldn't mind giving me a sense of where to start. |
I can't think of a case where However, I'm not sure why you'd want to use the Closure optimizations on asm.js code. If the |
In addition, I'm dubious that this would either: a. make a meaningful size difference in real world code In which case, is it worth the extra time or processing to handle this? See the required justifications at https://github.com/google/closure-compiler/wiki/FAQ#how-do-i-submit-a-feature-request-for-a-new-type-of-optimization |
Hi @MatrixFrog and @ChadKillingsworth. You're right, I ought to provide some context. At IMVU, we are building a 3D engine to render our content on multiple platforms, and, for the web, we compile it with Emscripten and then use Closure to minify. Emscripten has two compilers: the legacy one which has a couple different code generation modes, and the new 'fastcomp' compiler which only outputs JavaScript in asm.js-like syntax. Unfortunately, we can't use asm.js itself, as asm.js does not yet support growing the heap. To support our use case, the new 'fastcomp' compiler has an "almost asm" mode which DOES allow growing the heap, but otherwise the syntax reads like asm.js with (excessive, you could argue) type hints. It's true that running Closure on asm.js makes it not asm.js anymore :) but that's fine for our use case. We care more about download size and the time it takes for the browser to parse the JavaScript. OK, I hope that's enough context! @ChadKillingsworth I fully understand that this optimization would not affect typical programs, but because Emscripten compiles to "almost asm" and then runs Closure across it, redundant operators show up quite frequently. Does that help? Thanks! |
@chadaustin It does indeed. This can probably be done as a peephole optimization. See https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java for a starting point (you might just be able to add it to that file). Feel free to ask questions. Also, make sure you reference, add to and run the associated unit tests. |
I expect these will need to be handled on a case by case basis for these "type hint" operators but they are simple enough to add if someone wants to contribute patches. |
asm.js, from a strictly JavaScript perspective, produces a lot of redundant operators. For example, a function that takes a double and returns the same double would be expressed as:
Closure Compiler minifies that into:
Of course, the double + operator isn't necessary.
The text was updated successfully, but these errors were encountered: