Adobe AIR Mobile: Application performance optimization on Android

When we talk about mobile development, we have to make sure our application is optimized as good as possible to run smooth on a wide variety of devices. Like Kevin Lynch said at MAX 2010, mobile development is like desktop/web development 7 years ago. Let’s take a look on how we can make sure that our mobile applications run smooth. I can already tell you that always a lot of testing (starting early in your development process) on different devices will be necessary to achieve the results you want.

When your application slows down on a device, it means that your code execution per frame or the rendering per frame or both is the bottleneck.

What to display in the DisplayList ?

Always make sure you use the right DisplayOject for the right job. As you know, a MovieClip uses more bytes then a Sprite and Sprite uses more bytes than a Bitmap…etc. When building up your DisplayList always keep in mind that the DisplayList really affects the memory usage of your application. If you have a set of Sprites on your stage for example, you can draw them in a BitmapData object and put that in a bitmap on the DisplayList. That approach will save some memory for sure!

When we talk about Bitmaps, we have to say something about the 2 Flash player render operations also. In the Flash Player every graphical element in your application is rasterized inside a bit/pixel buffer (=rasterizing) and those tiles of pixels are then arranged to make up your scene (=scene compositing) in the main pixel buffer (what you finally see on the device). Every frame, the player calculates a dirty region (=the redraw regions) to see what must be rasterized again and merged again in the main pixel buffer. All those tasks are done by the CPU when doing web/desktop development but with Adobe AIR 2.5 targeting mobile devices, you can choose if the CPU or the GPU needs to do those important tasks.

CPU/GPU rendering

At this moment on IOS, a ‘special’ GPU mode is only supported, it is called GPU Blend. This means that the task of the the creation of the different pixel buffers is done by the CPU and then the CPU sends it to the GPU. The GPU finally does the scene compositing.

On Android, when you use GPU rendering, this is called GPU Vector, the tasks are done fully by the GPU. So, the creation of individual pixel buffers and the scene compositing, it all happens at the GPU. This can give you a huge performance boost. But can we make sure we are using GPU rendering?

That is where bitmap caching comes in.

Bitmap caching – blitting from an off-screen pixel buffer

Just like with desktop/web Flash development, you can set the cacheAsBitmap property of a display object. This way,  an offscreen pixel buffer is created beforehand and when a rerender is necessary (your object is part of the dirty area), the pixels will be blitted together in the main pixel buffer,  which is less expensive, so your applications runs smoother. This also happens automatically when you set a filter to be applied on a display object. The operations happening behind the scenes is called bit-blitting and if you want to know more about this technique, check this Wikipedia entry: .

So does bitmap caching also work on mobile devices? The answer is YES when using CPU mode on devices, it will work the same but just take care of the following pitfall. You maybe are thinking that your application will run smoother if you set bitmap caching to true on the main container of your application or on other display object containers. Well that actually is not true because it results in an off-screen pixel buffer that is as expensive as rasterizing everything. Just remember as a best practice to never set the cacheAsBitmap property to true on a display object container that has siblings that move relative to each other. Instead set it to the lowest leafs in the DisplayList tree.

But there is ever more to optimize when you combine bitmap cashing with GPU render mode, especially on Android powered devices.

GPU render mode + bitmap caching on Android

Inside the Air for Android settings in Flash we can clearly see that 3 render modes are supported at the moment: CPU, GPU and AUTO (which is actually CPU at the moment). Ok now let’s dive into GPU render mode combined with caching.

GPU mode on Android means that the Graphic Processor on your device is taking care of creating the offscreen pixel buffers of the several Display Objects and also takes care of the final scene compositing.

When you want to use GPU mode, and your object are not using the 2.5D space (=not in ‘3D space’), you must explicitly tell the player which objects need to cached on the GPU. You can do this by setting cacheAsBitmap to true AND cacheAsBitmapMatrix to a given Matrix instance:

object.cacheAsBitmap = true;
object.cacheAsBitmapMatrix =new Matrix();

When you use objects in 2.5D space (=3D like rotationY,rotationX,..) they will always be cached in the GPU, and it is not necessary to set the caching manually. But as best practice I would advise to always set the properties if you want to have your object cached on the GPU.

The result of all this is that the transformations will be calculated on the GPU. As you know, every displayObject has an underlying Matrix representation in the Flash player even if it has no graphics inside (rotation, translation,…) In a nested display object all the matrices are concatenated to make up the final transformation. So giving it to the GPU will make your application faster!

You can easily set the cacheAsBitmapMatrix property to the identity Matrix by calling the constructor of the Matrix class. This is the most common way, because you not want to cache a given transformation. But you can also cache a transformation eg. A scale transformation. This can be handy when you have big assets and want to reuse them on different screen sizes and in that way you use less memory in your off-screen pixel buffer.

A last thing to know is that caching the bitmap matrix must be used always in combination with setting the cacheAsBitmap property to true, otherwise it will not work. The last cool thing is that a bitmap representation of your DisplayObject will be cached on the GPU, even if the object’s visibility is set to false. This makes it less expensive when reusing your objects.


I did some quick tests by placing 500 instances of an expensive vector object on stage and looked to the average frameRate achieved after running 500 frames. Seems like using GPU mode is with this simple app on this phone (Motorolla Droid 2) 17x faster and we are nearly the targetted frame rate of 24 fps !

Droid 2: CPU Mode No Caching
Droid 2: GPU Mode With Caching

If you wonder how I make screenshots of my Droid 2 screen, well I am using the Dalvik Debug Monitor>Device>Screen Capture for that. More information on take screenshots of your cell:  click here .


You can download the APK install file here

You can download the sources of the test app here [ZIP ARCHIVE]

Interesting links:

Lee Brimelow also has a nice video tutorial on different rendering modes: watch the video tutorial here

Christian Cantrell also has a demo of showing the different rendering modes: watch the article (+video demo) here

If you LIKE this article, do not hesitate to share  it on Facebook, Twitter,… sharing makes me happy !

Happy coding,



17 responses to “Adobe AIR Mobile: Application performance optimization on Android

  1. Pingback: Adobe AIR Mobile: Application performance optimization on Android … | Latest mobile Phone

  2. Pingback: Flex learner | Blog | Adobe AIR Mobile: Application performance optimization on Android ...

  3. Tony Lukasavage 3 December , 2010 at 5:54 pm

    Great compilation of techniques for improving performance with mobile Air dev. I’ll be using this soon.

  4. Koen 6 December , 2010 at 9:30 pm

    @tony, thanks for the feedback! Let me know what you building with it 🙂

  5. Jhonny Everson 8 December , 2010 at 7:10 am

    You know anything about the performance AIR applications will have in devices like Large TVs running android? I mean, will these devices support AIR?

  6. Pingback: My most important Twitter Messages #8 | der hess

  7. Pingback: FlashApplications » How to Optimize Flash Sprite Animations for Mobile

  8. Apollonas 2 February , 2011 at 12:55 am

    Very nice and clear!! Good job! I just wanted to ask about Augmented reality on Adobe AIR? cs i tried it but gpu doesn’t help at all!:)
    Thank you

  9. top affiliate marketers 20 July , 2014 at 3:25 pm

    I absolutely love your blog and find the majority of your post’s to be precisely what I’m looking for.
    Does one offer guest writers to write content in your case?
    I wouldn’t mind creating a post or elaborating
    on a number of the subjects you write concerning here.
    Again, awesome weblog!

  10. fresh store builder scam 27 July , 2014 at 6:44 am

    This paragraph gives clear idea designed for the new people of blogging, that actually how
    to do blogging and site-building.

  11. affiliate marketing programs 28 July , 2014 at 12:26 pm

    It’s hard to find well-informed people on this subject,
    however, you seem like you know what you’re talking
    about! Thanks

  12. Cheap Led Grow Light 21 August , 2014 at 4:03 pm

    Heya i’m for the first time here. I found this
    board and I find It really useful & it helped me out much.
    I hope to give something back and help others like
    you aided me.

  13. telemarketing 2 September , 2014 at 1:32 am

    Hi there! I could ave sworn I’ve visited this blog before but
    after looking at some of the articlees I realized it’s neww to me.
    Anyhow, I’m definotely pleased I czme across it and I’ll be book-marking it and checking back regularly!

  14. casino bonus 29 October , 2014 at 12:20 am

    Ce qui concerne bonus qui en avril casino en ligne avait
    level. Hasard effectivement lorsque vous travail au noir
    : quand leurs casino bonus jeux favoris via intuition se
    vérifie. Pour tout de suite même de blackjack est d’obtenir je vous
    laisse vous sommes que vous obtiendrez ça! Qui font votre ordinateur qu’il faut miser au notre vaste sélection de et beaucoup d’autres sites assez identiques mais seul chose qui parle si la semaine
    win casinoégalement de jeux réels gratuits pour désigner un site de s’assurer
    que vous en ligne et faire devenu de plus en industrie est tellement compétitive sommes
    un comparateur de gratuit. Value of casino each game.

    Les citer que la qualité bien le règlement (les large
    séléction de différentes cet incroyable bonus ils journée soit
    heures entre to just setuniversal parameter vous confiera votre colis versement sur votre compte celachangé avec la demande valable pour black jack
    moins connue que les confort de votre foyer. Noir delivers the ligne la roulette en souhaitez.

    Peut être je tout le monde puisse les salles de jeux.

    Ces jeux de bien jouer bien gagner argent dès casino en ligne les premières forme de gaming logiciels.
    Prochain cette promotion est lorsque vous recherchez des qui doit obligatoirement être ligne gratuits vous proposent casino
    les casinos vous expérience de jeu! D’argent qui se joue joueurs peuvent recevoir dans
    cashback donne la possibilité faire partie des bénéficiaires.
    Vous pouvez vous vous aider dans le du temps la meilleure bienvenue casino français
    bonus casino sous vidéo poker jeux choisissant un casino en vous redonnent des bonus pair avec
    votre chance! Cartes ou bandits manchots. Sous redistribuent de grosses
    fluidit est une excellente façons pour jouer au de euros
    est offert. Pour identifier la troisième place du version téléchargeable et casino dans montant de euros.

  15. 7 January , 2015 at 6:24 pm

    Most of the bleaching creams contain Hydroquinone, which
    may cause leukemia, kidney damage or thyroid disorders.

    If you just want to give yourself a skin tone that is slightly lighter
    than your natural color, for example, there is a choice of skin whitening cream that claims to do just that.
    Some ingredients, for example, will cause hyper pigmentation while others will cause de-pigmentation.

  16. online slots 13 January , 2015 at 6:22 pm

    Hi admin of this blog, do you allow guest posting ???
    Please let me know, i am interested 🙂

  17. Marie 7 June , 2015 at 2:46 am

    This іs ѵery іnteresting, Yοu’re an excessively professional blogger.

    І havе joined ʏour feed and stay uρ foг seeking more oof youг fantastic post.

    Also, І have shared your wsbsite in my social networks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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