With some recent experience related to application performance, I thought to share some strategies to optimize performance of applications made with Flash Professional. There are two main components that determine Flash performance:
- CPU/GPU usage
- Memory usage
In this article I will begin with discussing memory management guidelines. Several times we are using filters, loops, Timers SoundChannels etc in Flash applications which are playing an important role in application performance.
Easiest techniques for performance optimization:
- Some objects or movie clips required just to represent some data, which doesn’t require user interaction in such cases normally we are not writing any code for that object. But still when user click on such object Flash Player checks for mouse interactions when these objects are present. You can save some CPU cycles by disabling mouse interactivity for objects that do not require mouse interactivity. Disable mouse interactivity.
- The issue with Timers is more critical. If a Timer has not stopped (because its currentCount is less than its repeatCount or because a stop() method has not been applied to it), the Timer will not respond to garbage collection even if you remove its listener and null all references. A Timer’s listener function won’t be called again once you remove the listener, but the Timer still consumes memory. Several times we start timer to achieve function requirement, and even after completion of the functional part execution the timer running. Explicitly stop Timers for garbage collection. However, if you open, play, and then close a Flash game running on a mobile device repeatedly without ever restarting the game, you may see a noticeable problem.
- For ENTER_FRAME event loop, (if required to use then only) use different listeners and different listener functions applied with related DisplayObjects only.
- Avoid use filters. Keep in mind that whenever you apply a filter to a DisplayObject in Flash, its cacheAsBitmap property gets forced to true and Flash must use memory to store that bitmap. If anything changes about that DisplayObject, like its transform operations like size or rotation or a child updates visually, etc, it must regenerate the bitmap, thus using more memory. That old bitmap hangs around until gc kicks in.
- Always use reverse for-loops. Avoid writing do-loops and while-loops.
- Using correct type of display objects for each element
- Use weak event listeners and remove listeners when no longer needed.
- Strictly type variables whenever possible.
- Explicitly disable mouse interactivity when mouse interactivity is not required.
- Replace dispatchEvents with callback functions whenever possible.
- Stop Sounds to enable garbage collection for Sounds and SoundChannels.
- Use the most basic DisplayObject needed for each element.
- Always use cacheAsBitmap and cacheAsBitmapMatrix with air apps (mobile devices).
- Several times when we are playing with loop and require to create object for each iteration in that case. In such situation it would be great if we create one object outside the loop and reuse it repeatedly in loop.
Friends, I hope these would be helpful to optimization of application performance. Feel free to share more ideas and comments about the topic.
Now Adobe Flash Player 11 and Adobe AIR 3 beta available for immediate download on Adobe labs at Flash Platform Runtime.
Adobe AIR 3 introduces enhanced features that provide developers a consistent and flexible development environment for the delivery of out-of-browser applications across devices and platforms.
AIR 3 delivers innovation for rich engaging applications with performance improvements that deliver advanced graphics rendering, high-definition video, and consistent reach across operating systems and devices. AIR 3 is packed with features that will benefit all developers but has a special focus for those interested in developing console quality games, delivering high quality video, or scalable enterprise applications.
Adobe Flash Player 11 desktop beta drives innovation for rich, engaging digital experiences with new features for cross-platform browser-based viewing of expressive rich internet applications, content, and videos across devices. Some of the features from the Flash Player Incubator, such as Stage 3D and 64-bit support, have been moved into this beta release.
Key benefits of the Flash Player 11 desktop beta include:
- Stage3D APIs :
Create highly interactive visuals to improve collaboration on 3-dimensional models.
A new set of low-level, GPU-accelerated 3D APIs that enable advanced 3D experiences and improved 2D performance across devices through the Adobe Flash Platform runtimes.
- 64-bit support:
Support for 64-bit operating systems and browsers on Linux, Mac OS, and Windows.
- G.711 audio compression for telephony:
Integrate voice/telephony into business apps using G.711 codec.
Support interoperability with legacy phone system (through Flash Media Gateway, FMG) and other third-party clients (through open RTMP protocol) without the need of transcoding.
- H.264/AVC SW Encoding:
Encode higher quality video locally using H.264 video.
Stream beautiful video from your computer’s camera with higher compression efficiency and industry-wide support, enabling both high quality real-time communications (e.g., video chat and video conferencing) and live video broadcasts from within Flash Player.
- Socket Progress Events:
Build advanced file sharing apps like FTP clients that send large amounts of data.
Provide a means by which content can determine how many bytes remain in the AS Socket’s write buffer. Provide an event which will inform content whenever data is removed from the AS Socket’s write buffer so that it may easily monitor the status of the write buffer without having to set up a timer and manually poll the size remaining in the AS Socket’s write buffer.
- HD surround sound:
As we know that Adobe released its own HTML5 video player, added HTML5 export tools to Adobe Illustrator and Dreamweaver CS5, and now Adobe showed a tool named “Wallaby” to converts Flash animation to HTML5. And the tool is still impressive.
Wallaby means that developers can easily reuse graphics and animation used in applications into HTML file.
So friends, Enjoy RIA..
Recently, at MAX adobe demonstrated it’s upcoming 3D API for Flash Player, code name ‘Molehill’ for a new set of low-level, GPU-accelerated 3D APIs which will enable advanced 3D experiences across screens through Adobe Flash platform runtimes and 3D engine developers the flexibility to leverage GPU hardware acceleration for significant performance gains.
You can observer the impressive video here on Adobe TV.
A video from MaxRacer demoed at Max Keynote Day 1, leveraging the upcoming 3D Molehill APIs :
From here you can get more information about how it works.
Packager for iPhone, a great feature of Adobe Adobe Flash Professional CS5 and Adobe AIR SDK 2.0.1, which offer developers a fast and efficient method to reuse existing code from projects to develop native applications on iOS devices.
You will get more information regarding iPhone applications development from below list :
1) Packager for iPhone developer guide – Details
2) Developing for iOS using Flash – Details
3) Optimizing content for Apple iOS devices – Details
4) Saving state in AIR applications for iOS devices – Details
5) Using screen orientation APIs for smartphone application development – Details
6) Guide for Apple App Store submissions – Details
You can download the Packager for iPhone from here.