On 7/19/16, 4:19 AM, "Harbs" <harbs.li...@gmail.com> wrote:

>I finally got my app to compile a release version by eliminating my
>circular dependencies. So far so good.
>
>FYI, I fixed this by doing two things: 1. I added a className property
>and instead of doing if(this is Sub), I’m using if(this.className ==
>“Sub”). 2. I enabled -js-output-optimization=skipAsCoercions (two of my
>circulars were due to an “as” statement which caused a circular
>dependency chain through a number of different classes).
>
>I have some observations / problems with the optimizations for the
>release build:
>
>1. It’s optimized to the point where it does not work. If I run
>MyApp.start() in index.html, I get an error that MyApp is not defined.
>Looking in the JS, I see that Em=‘MyApp’. Is there something special I
>need to do to prevent this from happening?

This usually means some exception was thrown at init time and MyApp never
got set as a exported symbol.  You have to eliminate all runtime
exceptions during class definition and prototype setup before MyApp is
defined.

>
>2. Prototype definitions are not being optimized as much as they could.
>The pattern is MyClass.prototype.foo = “some value”; for each one. If
>that’s replaced with MyClass.prototype = {foo:”somevalue”,…} It’ll save
>“MyClass.prototype” getting written for every property.
>
>3. Static constants are not being optimized as much as they should. I’m
>not sure what’s responsible for this, but instead of literals or compact
>variables, it’s using the fully qualified static name every time.
>
>4. Full class paths are not needed. The class paths could easily be
>shortened to a few unique characters for significant optimization. I just
>tried a search and replace on a 900KB file, and just replacing the
>package paths reduced the file size by 20KB.

We have currently chosen to export every public property in our
cross-compiled output.  That is done to support Reflection, and also to
support independently built modules someday.  The optimizer only knows how
to optimize the total set of sources given to it.  If a module developed
elsewhere gets loaded at runtime and makes a call, it won't know the
optimized variable used and needs to resolve the "old-fashioned" way.  We
could add new compiler options to get better optimization some day.

HTH,
-Alex

Reply via email to