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.
Application architecture is most important part for large scale enterprise application. You will get some important ideas about architecture from a small article on Application Architecture, which cover usage of application architecture and basic overview about PureMVC framework.
Sometime might be you feel that application’s same result will achieve by using MXML file without using such architecture. While probably it’s true for the small application, but keep in mind that a large scale application with a framework, will allows us to effectively communicate concepts and understands a code base quicker than an application without any design pattern and practice. In this article we are going to discuss about Robotlegs framework. So first lets start with what is Robotlegs.
Robotlegs is a great architectural framework for developing Flash, Flex, and AIR applications. It works for both Flash and Flex projects. Robotlegs is a mechanism for wiring your objects together. Robotlegs is a set of modular utilities and interfaces that provide tools to ease these communication tasks, reduce repetitive coding tasks, and manage dependency injection within your application.
The framework provides a default implementation based on MVC meta-design pattern. Robotlegs provides a prescriptive implementation of Model, View, Controller and Services (MVCS) implementation to get you start. If you have experience with PureMVC then you will quickly recognize the use of Mediators and Commands in Robotlegs framework MVCS design pattern. Robotlegs is a set of modular utilities and interfaces that provide tools to ease these communication tasks, reduce repetitive coding tasks, and manage dependency injection mechanism within your application.
You will get more idea from the Official Robotlegs MVCS Diagram:
Basic Structure of Robotlegs Application
A typical Robotlegs application is compose of several parts as:
2. Views & Mediators
3. Controller & Commands
Context is the heart of Robotlegs implementation. It’s bootstrapping mechanism that initializes dependency injection and the various core utilities that Robotlegs uses. The context provides a central event bus and takes care of its own startup and shutdown. A context defines scope. Also its possible to have several context within application.
Views & Mediators
A view is another name for a user interface. Basically anything that is an interface between your application and the user can be considered a view. They can should only read data from a model, not write directly to it.
The mediator’s job is to quite literally ‘mediate’ the view’s connection to the rest of the system. It listens to events coming from the global event dispatcher and then invokes the change on the view. It also listens to events occurring on the view itself and then alerts the rest of the system by dispatching an event on the global dispatcher.
Controller & Commands
The controller’s job is to manipulate data on the model, processing it beforehand if necessary. The controller is usually invoked by a view in response to user input. The controller never holds onto any data, it simply processes it then hands it on (usually to a model or service).
Commands are registered to a Context via that Context’s CommandMap. CommandMap is available by default in Context and Command classes. The Command class in RobotLegs contains a single execute method which is called immediately after instantiation. You use a Command class by overwriting the execute method with your own code. Commands are simple and shorted lived. Once a Command is instantiated and execute has been called its job is done. The CommandMap does not hold onto Command instances by default, they are left to the mercy of the garbage collector at this point.
Model’s role is to store state information within your application. This can be thought of as a place to store data that may need to be retrieved by another part of your program. Models send event notifications when work has been performed on the data model.
Robotlegs does not enforce the use of a specific Model class; any class can be treated as a Model. However, in order to gain access to the global EventDispatcher there is an Actor class which provides a single eventDispatcher property used to dispatch events to other actors in the system.
Service is use for service tier communication with external entity like Web Services, file access, or any action that takes place outside of the scope of your application for a service class. Service classes dispatch system events in response to external events.
Conceptually there are many similarities between the service and model tiers in MVCS architecture. Because of this similarity, models and services are extended from the same base Actor class.
You will get more information about Robotlegs framework from here.
Enjoy RIA ..🙂
At its MAX 2011 technology conference, Adobe announced that LG and TiVo have become the latest partners to bring Adobe Flash-based applications via Adobe AIR to connected TVs and digital home devices. Content partners can now take advantage of AIR to deliver Flash-based console-quality gaming and premium video across TVs, Blu-Ray players and set-top boxes.
Adobe also announced that Flash Player 11 and AIR 3 will be available today, a milestone release that will enable the next generation of immersive application experiences across devices and platforms. As announced, dozens of new features allow developers to deliver a new class of gaming and premium video experiences, as well as sophisticated, data-driven apps with back-end systems integration across devices and platforms including Android, Apple iOS (via AIR), BlackBerry Tablet OS, Mac OS, Windows and connected TVs and others. AIR Apps available on Samsung SmartTVs, coming to Digital Home devices from LG, TiVo and others.
Demo video of Flash-based apps with 3D graphics and others running on a Samsung Smart TV and other devices:
With more than 100 unique digital home devices already certified to support Adobe Flash and AIR, including Samsung Smart TVs, Adobe expects rapid growth for Flash-based applications across connected televisions and other devices.
TVs and other connected devices in the digital living room are the next frontier for rich entertainment apps. Flash-based applications are transforming content consumption on TVs as developers embrace new opportunities to deliver beautiful HD content to increasingly powerful digital home devices connected to a big screen.
With the AIR SDK, Flash Builder and Flash Professional CS5.5 software, developers can build new applications for connected digital home devices or extend existing Flash-based experiences from desktops and mobile devices to TVs. AIR 3 brings a series of advancements to TVs including full hardware-accelerated rendering for 2D and 3D graphics to enable console-quality gaming applications. Content publishers are able to deliver HD videos with Dolby and DTS 7.1 channel surround sound for full support of home theater systems. With the new Game Input API, developers can also make a range of devices an integral part of the gaming experience on TV screens, including joysticks, smartphones and tablets.
Flash Player is supported on more than 98 percent of Internet connected PCs today and by the end of 2011, Adobe expects more than 200 million smartphones and tablets including Apple iOS devices to support Flash based applications via AIR. By the end of 2015, the number of devices that will support AIR is expected to increase to 1 billion. AIR, a superset of Flash Player, enables developers to leverage existing code to create and deliver standalone applications across devices and platforms. Thousands of Flash-based applications have already been created and made available on Android Market, iTunes App Store, Samsung SmartTV Store and BlackBerry AppWorld today.
You can get MAX keynote information from here.
Enjoy RIA .. :)
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:
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.
I think this year will be great and superb time for developers working on Adobe technology, mainly Flash and Flash Builder. As Adobe MAX 2010 Kicks Off, so will get more interesting information for mobile application development and adobe technologies. Let me focus on Mobile application :
Mobile development features in “Hero” and “Burrito” are targeted at creating standalone installed applications using the Adobe AIR runtime for mobile devices. By focusing on AIR, Flex can take full advantage of the integration AIR provides with each mobile platform, such as the ability to handle hardware back and menu buttons and to access local storage.
Burrito” release of the Flash Builder IDE brings a productive design/build/debug workflow to mobile development. From project creation to visual layout to one-click debugging and deployment on devices, the aim of the mobile features in “Burrito” is to make it just as easy to develop an ActionScript- or Flex-based mobile application as it is to develop a desktop or web application.
So its realy rocking time for Flash, Flex Developers. You will get superb information related to Mobile application development and code productivity enhancements and new Spark components information from videos and articles listed below:
- Beginning a Mobile Application – Video
- Navigation and Lists for Mobile Application – Video
- Debug and package Apps for Devices – Video
- Code Productivity in Flash Builder – Video
- Code Productivity in Flash Builder – Article
- New in Flash Builder “Burrito” – Article
- Spark DataGrid Component – Video
- Spark Form Container – Video
- Spark Image and BitmapImage – Video
- Spark Formatters – Video
- Flash Builder and Flash Catalyst Designer Developer Workflows – Video
- Mobile Development using Hero and Flash Builder “Burrito” – Article
- Adobe AIR coming to TV – News Article
Enjoy RIA ..🙂