10 Replies Latest reply on Jul 19, 2011 5:41 PM by ReloeccX

    Optimize Framerate? (1000th of Objects)

    ne_polle Level 1

      Hi all

       

      I created an App which is drawing thousands of Canvas Objects.

       

      When I move my Mouse about the App without any Objects the framerate is normal (60fps).

       

      When I move my Mouse about the thousands Objects the framerate goes down (4000 objects > t20fps).

       

      I tried to deactivate the mouse interaction of all objects:

      mouseChildren = false;
      mouseEnabled = false;
      mouseFocusEnabled = false;

       

      Framerate goes also down.

       

      What should I do to get the normal framerate back??

       

       

      thanks for any advice.

      best regards

      julia

        • 1. Re: Optimize Framerate? (1000th of Objects)
          Flex harUI Adobe Employee

          Don't have as many objects.  Why do you have so many?

          • 2. Re: Optimize Framerate? (1000th of Objects)
            Lee Burrows Level 4

            if your objects arent scaling or rotating, setting cacheAsBitmap = true on all your objects should help

             

            or if none of them are moving either, you can just set cacheAsBitmap = true on their container object

            1 person found this helpful
            • 3. Re: Optimize Framerate? (1000th of Objects)
              ne_polle Level 1

              I need to create a lot of Objects for an project. Each Object has some mouse interaction (e.g. highlights when rollover/rollout)

               

              I try to optimize this app couse I have so many objects.

              I'm thinking about to give mouse interaction just objects which you can see in the current cutout.

               

              The advice to use cacheAsBitmap was helpfull. Now the framerate is nearly by 45fps. thanks!

               

              Some other ideas??

              Any advice is welcome to speed it up. :-)

              • 4. Re: Optimize Framerate? (1000th of Objects)
                ipauland Level 1

                ne_polle wrote:

                 

                I need to create a lot of Objects for an project. Each Object has some mouse interaction (e.g. highlights when rollover/rollout)

                 

                I try to optimize this app couse I have so many objects.

                I'm thinking about to give mouse interaction just objects which you can see in the current cutout.

                 

                The advice to use cacheAsBitmap was helpfull. Now the framerate is nearly by 45fps. thanks!

                 

                Some other ideas??

                Any advice is welcome to speed it up. :-)

                 

                It's ridiculous to try and have mouseover handlers for 4000 active objects - I'm surprised it works as well as it does.

                 

                See how much your performance improves when removing the rollover/rollout handler.

                 

                If performance is boosted consider using a single enterframe handler to detect when the mouse is over an object. You can do this by sorting the objects x positions in an array and then looking for a match on y too. Just do a proximity calculation on the (x,y) to see if a rollover is happening. A bit more logic will give you a rollout effect too.

                 

                Paul

                • 5. Re: Optimize Framerate? (1000th of Objects)
                  ipauland Level 1

                  A hybrid strategy is to turn on and off the rollover/rollout handlers for objects within a certain proximity to the mouse. This will greatly reduce the number of active objects available torespond to mouse events.

                  • 6. Re: Optimize Framerate? (1000th of Objects)
                    ne_polle Level 1

                     

                    It's ridiculous to try and have mouseover handlers for 4000 active objects - I'm surprised it works as well as it does.

                    Yes the interaction still work also with alot of more objects e.g. 10000 objects.

                    The App has just a low framerate

                    See how much your performance improves when removing the rollover/rollout handler.

                    of course I'm adding and removing the whole eventlistener of each object

                    But thanks for the advice.

                     

                    I tried to add the whole mouse interactivity just objects within a specific cutout.

                    Result: Of course it effects positively the framerate :-)

                    If performance is boosted consider using a single enterframe handler to detect when the mouse is over an object. You can do this by sorting the objects x positions in an array and then looking for a match on y too. Just do a proximity calculation on the (x,y) to see if a rollover is happening. A bit more logic will give you a rollout effect too.

                    I will try that. thanks.

                    • 7. Re: Optimize Framerate? (1000th of Objects)
                      Flex harUI Adobe Employee

                      Check your memory consumption if you turn on cacheAsBitmap for 1000's of

                      objects.  You might just be trading off one problem for another.

                       

                      Unless your display has unusual specifications, it would normally be

                      difficult, if not impossible, to target 1000 individual buttons on a screen.

                      They would be very small, or partially obscured such that their physically

                      targetable area would be small.

                       

                      In Flash, there are Sprites (UIComponent and most of Flex is based on

                      Sprite) and Shapes.  Shapes are much lighterweight, but are not individually

                      targetable.  However, it might improve performance to use Shapes and do

                      individual hit testing, or just draw graphics directly into a Sprite (which

                      is what Spark Group tries to do) and do individual hit testing.

                       

                      When you have a lot of Sprites, the player is checking each one on each

                      frame to see if it has a framescript.  If your frame rate is 24 and you have

                      1000 sprites, you've essentially added a for loop from 1-24000 in your app.

                       

                      Then, when you move the mouse, each sprite is tested for the hit.

                       

                      Then, if you change visuals, each sprite and shape is tested to see if needs

                      redrawing.

                       

                      As you can see, that is a lot of loops.

                       

                      Now, if lots of these objects are off-screen or completely obscured, it is

                      often better to "virtualize" and only create Sprites for the objects that

                      are visible.  All of the Flex list classes have a mode like that, otherwise

                      data sets of 10000 items would destroy performance.

                      • 8. Re: Optimize Framerate? (1000th of Objects)
                        ne_polle Level 1

                        thanks for your detailed answer.

                         

                        Now, if lots of these objects are off-screen or completely obscured, it is

                        often better to "virtualize" and only create Sprites for the objects that

                        are visible.  All of the Flex list classes have a mode like that, otherwise

                        data sets of 10000 items would destroy performance.

                         

                        for "virtualize" I found this nice example:

                        http://www.developria.com/2009/08/using-virtualized-layouts-and.html

                         

                        Is this just for spark objects possible?

                         

                        hmmm how does the virtualize methode work when I'm using a UIComponent as the Container for all my small interactive Objects (e.g. also UIComponent)?

                        I need to position each interactive object individually.

                         

                        does the option "includeInLayout" effects the framerate??

                        • 9. Re: Optimize Framerate? (1000th of Objects)
                          Flex harUI Adobe Employee

                          IncludeInLayout is primarily for Containers/Groups.

                           

                          If you using it on UIComponents containing UIComponents, it probably won't

                          make much of a difference.

                           

                          MX DataGrid and List are examples of UIComponents that use virtual layouts.

                          Essentially, they keep a database of what objects should be where, but only

                          create renderers for the ones you can see.

                          • 10. Re: Optimize Framerate? (1000th of Objects)
                            ReloeccX


                            Hello, too late? (answer for others, probably)

                             

                            You should to set

                                 mouseChildren = false;
                                 mouseEnabled = false;

                             

                            for container (too), not for each of your object.