Top 10 Performance Tips for 2012

  1. Use native code instead of AS3Generally, it’s better to let Flash Player’s native code do the heavy lifting rather than using AS3. The reason for this is that the VM that AS3 code runs in necessarily has some overhead to it compared to the functions you can call in the Flash Player API (everything in the flash.* packages). One exception to this rule is when the API does something you want to avoid such as allocate memory.
  2. Eliminate allocations to reduce GCIn addition to the allocations that you expect—such as those that you trigger by using the new operator—there are tons of hidden allocations such as String objects from concatenation, objects the Flash Player creates such as Events. These allocations are slow and collecting them when you’re done with them is even slower, so try to get rid of them.
  3. Reuse objects to reduce GCWhen you’re done with objects, Flash Player’s garbage collector will reclaim their memory for reuse later. Unfortunately, this process is very slow and it’s hard to control when it will happen. Instead of making new objects, consider reusing existing ones. One technique that can help with this is called free lists.
  4. Don’t use anything dynamicThat includes dynamic functions (e.g. anonymous functions and functions declared as local variables), objects such as Object and MovieClip, the [] operator for accessing fields, and untyped (*) variables. All of these are much slower than their static equivalents such as regular methods, non-dynamic classes, the dot operator, and typed variables.
  5. Offload to the GPUThese days in Flash you have the ability to use video cards’ GPUs in addition to the main CPU. Using a combination of these is the key to high performance with 3D graphics (Stage3D) and high-definition video (StageVideo).
  6. Reduce function callsFunction calls are, very unfortunately, quite slow in AS3. This includes getters and setters, which occur all the time (e.g. Array.length). Try caching the results of functions instead of calling them more than once, especially with getters. In extreme cases, manually inline the body of functions into one larger function.
  7. Use speciality functions and classes rather than general purpose onesSprite uses less memory than MovieClip, Shape uses less memory than Sprite, and BitmapData.copyPixels is faster than BitmapData.draw.
  8. Use fewer static accessesAccessing static variables, constants, and functions is slower than accessing their non-static counterparts. Consider using non-static alternatives or caching those static accesses as either non-static variables/constants or local variables/constants.
  9. Prefer local variables to fieldsReading and writing class and object variables (a.k.a. fields, member variables) is much slower than accessing local variables. Cache field accesses as local variables when you use them a lot.
  10. Eliminate pointless codeIt’s common to see variables initialized to their default value, which slows down the creation of objects and the execution time of functions. Get rid of this code that does nothing as a matter of good habit and the performance advantages will add up across your entire app.
Advertisements

About Saran

Hello there!!! I'm Saravanan, born and living in India. The main reason i decided to start this project it was because there should be a way to transfer my knowledge which i experimented in flash to all. i try to concentrate as much as possible all kind of issues can appear to someone is developing an Flash application. If you need help, or if you would like to see in this blog some issues, send me an e-mail to rksaran@rediffmail.com Follow Me: twitter:http://twitter.com/rksaran Best Regards, SRK
This entry was posted in Flash, Flex. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s