Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMinimize the number of IIFEs generated by Desugar for Closure IR nodes #2675
Comments
I don't really understand what you want Scala.js to do here? Could you make that more precise? We don't develop Closure, so changing what it does is not within our ability. |
It's also not clear to me what "the ECMAScript 2015" code is. Generated how, by what, from what? |
I mean some benchmarks run faster with the option I noticed that Closure Compiler supports ECMAScript 2015 input format. I wonder if we could enable Closure Compiler for |
It doesn't, so that's not the actual reason. The actual reason is that Closure typically degrades performance a bit, up to 50% in some of our benchmarks. If you want to fairly compare the ES5 version versus ES2015, you should either compare their That said, we should indeed enable Closure in the ES2015 output now that it supports it. |
@sjrd I re-checked the ECMAScript 2015 output. You are right, there are many IIFEs in the output. I used to think that ECMAScript 2015 target does not use IIFE in favor of |
AFAIK, the Scala.js compiler inline regular functions, however, it brings more IIFE function calls. |
In general, they are necessary so that captures are truly immutable (and not a read-only version of a variable whose value changes in each iteration of a loop). Not all of them are necessary. A more sophisticated translation in |
I noticed that Scala 2.11.x does not create IIFEs (creating prototype classes instead), and has better performance for most cases than Scala 2.12.x. |
The result of the benchmark can be found at https://atry.github.io/scala-js/table.html , and the source code is at https://github.com/krausest/js-framework-benchmark You may notice that Scala 2.12 is slower than 2.11 for almost every benchmark and consumes 122% memory comparing to Scala 2.11 version. |
Could you also benchmark with 2.11 with the |
Yes, Scala 2.11 with |
Thanks. I guess it would be worth trying to improve the emitter about that, then. |
@sjrd , As long as Closure compiler supports ECMAScript 6 input, which allows scoped |
With the |
Is this still an issue? My understanding of the discussion is that using ES6 entirely mitigates the need for this. @sjrd This had me toying with the idea of always generating ES6 when using closure and have closure compile ES6 down to ES5.1. This would:
WDYT? |
In turn, we configure closure to compile ES6 down to ES5. This gives closure more structured information about the relevant trees. As a side-effect, this fixes scala-js#2675.
In turn, we configure closure to compile ES6 down to ES5. This gives closure more structured information about the relevant trees. As a side-effect, this fixes scala-js#2675.
In turn, we configure closure to compile ES6 down to ES5. This gives closure more structured information about the relevant trees. As a side-effect, this fixes scala-js#2675.
ES6 has the features that would allow us not to generate IIFEs, but we don't leverage them.
In general, one cannot compile down ES 2015 semantics entirely accurately to ES 5.1. There are choices involved, and not all compilers agree. We cannot guarantee that GCC makes the same choices (and will continue to make the same choices) regarding the particular semantics to give to things that do not have an exact equivalent in ES 5.1. Therefore I think that giving ES 2015 to GCC while we give ES 5.1 in fastOpt would be dangerous. We could leave things go unchecked/broken in production mode. |
Was: Scala.js with Scala 2.12.0 creates too many unnecessary IIFE
I created a web framework Binding.scala, which generates deeply nested blocks for XHTML literal.
These kind of blocks will be converted to IIFE for ECMAScript 5 like this:
The entire JS file can be found at https://github.com/ThoughtWorksInc/todo/blob/3f173cd/js/js-opt.js
These IIFEs are very slow. In some benchmarks, even the output ECMAScript 2015 code (which creates
const
instead of IIFE) with fast optimizer runs two times faster than ECMAScript 5 code with full optimizer!I expect that Closure Compiler would inline IIFE, or enabling Closure Compiler for ECMAScript 2015.