birth background
Adobe's Flash compiler (ASC, ActionScript Compiler) is too "yesterday" in performance, and the Flash virtual machine still has a lot of room for improvement in performance. Flash is often treated as a toy or jokingly called a CPU hog. Generally speaking, we rarely optimize a SWF manually. In most cases, it can run well, but when the size of a SWF file is too large, the loading time is too long, or the code execution time is too long, causing the frame rate to be too high. When it is low, we need to consider optimizing SWF, such as streamlining the code and compressing static resources (pictures, videos, etc.). However, the performance improvement produced by manual optimization is very limited. More optimization tasks should be left to the compiler. Thankfully, the Apparat framework can help us free ourselves from the nightmare of manual optimization. Not only that, any future All optimized SWFs can be optimized from it. Joa Ebert, the author of Apparat, has profound insights into the field of Flash performance optimization. At this year's FlashAndTheCity conference, joa's outstanding work won him two awards : "The Most Genius Flash Developer in 2010" and "The Most Outstanding Contributor in 2010" Grand prize.
Build environment
The Apparat framework is written through Scale. Before practicing it, you need to install Scala 2.8.0 and Java 1.6. The installation of 7-zip is optional. After setting up these basic operating environments (which need to be added to the PATH environment variable), the latest installation package (currently 1.0RC8) can be downloaded from Google Code . After downloading, extract it to a new folder. The files included are:
Apparat provides many command line tools, such as tdsi, stripper, reducer, etc., as well as some very special ActionScript APIs (existing in SWC files). Next, let’s take a look at how Apparat speeds up Flash.
Optimize bytecode
The core function of Apparat is TAAS (Three Address ActionScript Compiler). TAAS will not change any line of ActionScript. It can obtain considerable performance improvements by just using ordinary optimization techniques. Different from Adobe's compiler ASC, Apparat analyzes, reorganizes and reassembles compiled SWF and SWC files.
The bytecode in the Flash virtual machine AVM is based on stack. This structure is difficult to optimize. Apparat first converts the stack-based bytecode into CFG (Control Flow Graph), and then converts it into stack-less TAC through CFG. (Three Address Code) code, that is, TAAS (Three Address ActionScript).
With TAC/TAAS, Flash bytecode can be re-optimized based on compiler optimization techniques, such as inline expansion , copy propagation , constant folding , dead code elimination , etc.
Apparat provides several useful SWC files with more efficient APIs, and even includes Alchemy APIs that are not yet available in ActionScript. After SWF using these APIs is processed by Apparat, the execution efficiency will be greatly improved. The principle is that Apparat performs inline optimization on the corresponding code. The command format for optimizing bytecode is:
tdsi -i input.swf -o output.swf
Source: Koubei.com UED Team