7 Replies Latest reply on Feb 1, 2011 11:37 AM by bananax182

    Performance Optimization (Vector vs Raster)

    bananax182

      Hello public,

       

      I am trying to improve the frame rate of a game that draws many floor tiles. Currently, the floor tiles are vector graphics and stored as different frames in a movie clip. I wanted to experiment with rasterizing a floor tile and seeing if that would provide any frame rate boosts. I did this by converting one of my tiles (one of the frames in my movie clip) to a png and replacing the vector version of this tile with this raster version. I then tested two worlds--one filled with tile A (vector) and another filled with tile B (png).

       

      In all my tests, world with tile A (the original vector version) outperformed the world with tile B. I am guessing that the reason I am not getting the expected performance gains is because I am still rendering the tiles in the old style and not using any strict bitmap drawing calls?

       

      Can someone help me get a better understanding of why it is that this method fails to boost rendering speed? Would I have to switch my rendering code to strict bitmap draw calls? Any insight or links to relevant articles or sites would be greatly appreciated. Thanks, all.

        • 1. Re: Performance Optimization (Vector vs Raster)
          kglad Adobe Community Professional & MVP

          check the cacheAsBitmap property of bitmaps to see if this will benefit performance in your app.

          1 person found this helpful
          • 2. Re: Performance Optimization (Vector vs Raster)
            bananax182 Level 1

            Actually, now that you mention it--it seems like the cacheAsBitmap flag was already set. I'll be sure to mark your response as the answer to this question. First though, I want to be sure I am clear of what is going on.

             

            Here's my best assessment on why the vector tiles were rendering quicker than the raster tiles:

            - Flash caches the draw data for tiles as a bitmap after drawing the first one--effectively performing the raster optimization I was trying to perform by rasterizing the asset itself.

            - Every time the a tile is scaled (zooming) or an animated movie clip plays in front of a tile, that tile has to be redrawn as the vector version. However, the time savings of the rest of the cached tiles negates the performance decrease of these few vector tiles--yielding a net benefit from using the cached bitmaps

            - Still unknown--why do my rasterized tiles not perform identically to my attempted raster version. Both have cacheAsBitmap on, so should behave almost exactly the same?

             

            Thanks!

            • 3. Re: Performance Optimization (Vector vs Raster)
              kglad Adobe Community Professional & MVP

              cacheAsBitmap is a detriment to performance if the object is being scaled (or rotated or faded etc).  cacheAsBitmap is a significant help if the object, at most, changes x,y properties.  otherwise the bitmap must be redrawn.

              1 person found this helpful
              • 4. Re: Performance Optimization (Vector vs Raster)
                bananax182 Level 1

                Any ideas why having cacheAsBitmap on in both cases still ends up with the vector tiles rendering faster? My understanding of cacheAsBitmap is that it is a detriment to performance if the object is scaled, non-static, has a non-static asset in front of it in the same redraw region, etc. However, if it is on in both cases...shouldn't the two tests perform similarly? Right now, vector tiles draw 13% faster. Again, the only difference between both tests is that the movieclip in the vector version contains vector art vs. the movieclip in the raster version contains a png.

                 

                In fact, now that I think about it...shouldn't the raster version STILL outperform the vector version if both have cacheAsBitmap set?

                 

                Vector version - a redraw region is invalidated because of an animation or scale. Flash cannot use the cached version of the tile, so must redraw all vectors and maybe recache.

                 

                Raster version - a redraw region is invalidated because of an animation or scale. Flash cannot use the cached version of the tile, so must redraw a png and maybe recache.

                 

                I thought that when all things were the same, flash was more effecient at drawing a png vs a vector graphic?

                 

                Edit: Thanks again, by the way. I am sorry if I sound persistent--I just want to make sure that I truly understand what is going on under the hood.

                • 5. Re: Performance Optimization (Vector vs Raster)
                  kglad Adobe Community Professional & MVP

                  in most situations you would expect any non-translational transform (ie, everything other than an x,y change) to demand less computer resources when applied to a vector vs a bitmap whether cacheAsBitmap is applied to both or applied to neither.   you would expect each to use less resources during non-translational transforms when cacheAsBitmap is disabled.

                  • 6. Re: Performance Optimization (Vector vs Raster)
                    bananax182 Level 1

                    Thanks for all the help

                    • 7. Re: Performance Optimization (Vector vs Raster)
                      kglad Adobe Community Professional & MVP

                      you're welcome.