Wednesday, August 12, 2009

Ideas for optimizing flash / flex applications

Optimizing the memory consumption, processor cycles used and even user experience in a flash application is as complex as it is important. Not very many projects out there reserve time for the explicit task of optimizing the application, which is why I think developers should incorporate some of these techniques in their daily development, or in the initial planning of the architecture of the application.

A good place to start for optimization advice is Adobe's advice for reducing SWF file size in Flex applications. A lot of the ideas there pertain well to improving user experience as well - as is, for instance, splitting the application in modules, loading external swcs, and loading content at runtime where possible. Adobe also offer a rather valuable tool for Flex developers, the linker dependencies xml which you can export as part of the compilation process. Here's an AIR application called AIR Link Report visualizer which will spare you from having to read plain xml by presenting dependencies in nicely arranged lists and offering a nifty visualisation chart showing you the breakdown of the packages used in your application.

User experience is given a lot of attention in this tutorial about SWF framerate optimization done by Lee Brimelow.

As processor cycles are concerned, it usually comes down to fine-grained changes in your code. For me, this is the fun part.
Depending on your current knowledge, you might want to start off with Grant Skinner's great presentation about resource management.
A comprehensive list of possible code optimizations is maintained by Joa Ebert, read it with both eyes. Also watch out for valuable links to more details on particular subjects, such as this list of bitwise operations: Bit Twiddling Hacks. Next, you can get your head around the debate about the int / uint / Number types in Flash by reading Grant Skinner's discussion on them (prompted by this blog post), and this post which also looks at flash player versions for a more detailed approach.

I will keep adding to this list as I discover new articles on the topic. If you have your favourites, show them off.

No comments: