Flash & Actionscript Performance Tunning Notes

Flash ve Actionscript için performans düzenlemesi adına yaptığım araştırmalar sonucu bulduğum dokümanlardan aldığım notları orjinal halleri ile aşağıda paylaşıyorum. Bir çok detay var ama ince ince bu dokunuşları yapmak ve karşılığını görmek tatmin edici oluyor.

  • This code sets framerate to 24 and should be written in document class
  • [SWF(frameRate="24")]
  • For simple shapes that are not interactive, use Shape objects. For interactive objects that don’t need a timeline, use Sprite objects.
  • Use the getSize() method to benchmark code and determine the most efficient object for the task
  • Set the reference to null, so that the garbage collector removes  the display object from memory
  • Using vectors instead of bitmaps is good way to save memory. However, using vectors, especially in large numbers, dramatically increases the need for CPU or GPU resources. Using bitmaps is a good way to optimize rendering, because the runtime needs fewer processing resources to draw pixels on the screen than to render vector content
  • When a filter is applied to a display object, the runtime creates two bitmaps in memory. These bitmaps are each the size of the display object. The first is created as a rasterized version of the display object, which in turn is used to produce a second bitmap with the filter applied.
  • If the filter is not modified within 30 seconds, or if it is hidden or offscreen, the memory used by the non-filtered bitmap is freed.You may use loops more than 30 seconds.
  • <param name=”hasPriority” value=”true” />
  • This feature allows you to limit CPU usage by pausing and resuming the SWF file when content goes off and on the screen.
  • Minimize the number of Timer objects and registered enterFrame handlers in your application.
  • Use a single Timer object, and have operations triggered at multiples of the Timer object’s delay property interval
  • In enterFrame event or Timer handlers, minimize the number of changes to the appearance of display objects that cause the screen to be redrawn
  • To save CPU power, limit the use of tweening, which saves CPU processing, memory, and battery life.
  • When working with the text property of the TextField class, use the appendText() method instead of the += operator. Using the appendText() method provides performance improvements.
  • Use redraw regions to identify opportunities for optimization. (Right Click on swf than choose Redraw Regions) Remember that although some display objects are not shown, they still consume CPU cycles because they are still being rendered.
  • To improve performance, set the visible property of the hidden running character to false or remove it from the display list altogether. You should also stop its timeline. These steps ensure that the display object is frozen and uses minimal CPU power.
  • If possible, try not to place graphical content off-stage. Designers and developers commonly place elements off-stage to reuse assets during the lifetime of the application. Even if the off-stage elements are not shown onscreen and are not rendered, they still exist on the display list. The runtime continues to run internal tests on these elements to make sure that they are still off-stage and the user is not interacting with them.
  • If your application includes animation, an adequate frame rate is at least 20 frames per second. Anything more than 30 frames per second is often unnecessary.
  • If your application doesn’t include animation, a frame rate of 12 frames per second is probably sufficient.
  • A good optimization can be made by using the bitmap caching feature. This feature caches a vector object, renders it as a bitmap internally, and uses that bitmap for rendering. The result can be a huge performance boost for rendering, but it can require a significant amount of memory. Use the bitmap caching feature for complex vector content, like complex gradients or text.
  • However, if bitmap caching is enabled on a display object such as a movie clip that has its timeline playing, you get the opposite result. On each frame, the runtime must update the cached bitmap and then redraw it onscreen, which requires many CPU cycles. The bitmap caching feature is an advantage only when the cached bitmap can be generated once and then used without the need to update it.Changing the x and y properties of the object does not cause regeneration. However, any attempt to rotate it, scale it, or change its alpha value causes the runtime to regenerate the cached bitmap, and as a result, hurts performance.
  • Avoid using filters on animated content, because it can cause performance problems.
  • Use the bitmap caching feature and the opaqueBackground property to improve text rendering performance.
  • GPU mode is set automatically when running content on mobile devices, for the best possible performance. Although wmode no longer must be set to gpu to get GPU rendering, setting wmode to opaque or transparent disables GPU acceleration.
  • Smooth shapes to improve rendering performance.By using the Smooth tool in Flash Professional. Smoothing removes extra control points, reducing the final size of the SWF file and improving rendering performance.
  • Starting with Flash Player 9.0.115.0 and AIR 1.0, the runtime can play AAC files (AAC Main, AAC LC, and SBR). A simple optimization can be made by using AAC files instead of mp3 files.The AAC format offers better quality and smaller file size than the mp3 format at an equivalent bitrate.
  • To save memory, use the cacheAsBitmap property and activate it on each display object rather than on the container.Changing the alpha value forces the runtime to update the cached bitmap in memory whenever the alpha value is modified.

    For more:
    http://help.adobe.com/en_US/flash/cs/using/WSd60f23110762d6b883b18f10cb1fe1af6-7b1ba.html

    NMPress by Mahmut Çanga