Using the FlexBuilder "-link-report" compiler option to generate ActionScript size report

October 13, 2008 12:42 by docbliny 

I'm working on a pretty cool ActionScript 3 based project and we're trying to optimize the size as much as possible. Pretty much everything is rendered in code and we noticed that the AS compiler is actually pretty bad at optimizing the SWF. For example, it seems to not touch class level private variable names, thus keeping the actual strings intact which increases both the SWF size and memory usage pretty drastically if there are lots of instances of the object in memory. I don't have any hard numbers to share, maybe I'll get around to creating a sample project to get some numbers I can share.

Setting Compiler Options 

In the meantime, you can at least get a sense of where the size of the SWF is coming from by using the -link-report [filename] compiler argument. In FlexBuilder, you can set it under the ActionScript Compiler page in the Additional compiler arguments field.

Link Report File 

The resulting XML file contains a list of all ActionScript files, their size, optimized size and a list of all dependencies. For example:

<report>
  <scripts>
     <
script name="Drive:\Path\MyProject\src\accessibility\ComboBoxItemAccessibility.as" mod="1217893038671" size="1593" optimizedsize="875">
       <def id="accessibility:ComboBoxItemAccessibility" />
       <
pre id="accessibility:ButtonAccessibility" />
       <dep id="flash.events:MouseEvent" />
       <
dep id="accessibility:Constants" />
       <dep id="MenuItem" />
       <
dep id="AS3" />
    </script>
  </scripts>
</report>

The most interesting items are the size and optimizedsize attributes.

Using an XSLT File to Improve Readability

The link report file can be pretty large and hard to read, so I put together a really crude XSLT file to transform the report into HTML. You can then easily drop the HTML file on Excel to sort by the size and see which classes might be good candidates to optimize.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="yes"/>     <xsl:template match="@* | node()">
    <xsl:copy>
     <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>

    </
xsl:template>
    <xsl:template match="/">
       <html>
        <body>
          <h2>ActionScript Link Report</h2>
          <table border="1">
             <
tr>
               <th align="left">Name</th>
               <th align="left">Size</th>
               <th align="left">Optimized Size</th>
             </
tr>
            <xsl:for-each select="report/scripts/script">
             <
tr>
               <td><xsl:value-of select="@name"/></td>
               <td><xsl:value-of select="@size"/></td>
               <td><xsl:value-of select="@optimizedsize"/></td>
            </
tr>
         </xsl:for-each>
         </
table>
      </body>
    </html>
 
  </xsl:template>
</xsl:stylesheet>