7 Replies Latest reply on Sep 25, 2006 1:38 AM by Newsgroup_User

    setInterval - CPU loading issue

    NoNameNoPackDrill
      I have a Flash application nearing completion I am getting ready to go into its first pilot site - so am doing alpha testing with a few family members...

      Everything works pretty well but testing by my son has thrown up a wierd CPU loadind issue - I will try to explain...

      In part of my Ap I am using lineto to draw shapes on the screen with sets of coordinates, pre loaded into arrays. I load setInterval with a different millisecond value to change the speed of drawing said shapes then each time it is called it picks up a new coordinate from the array and lines to that. Once an incremented counter hits the end of the array, I clear the current setInterval and pick up a new set of coords and begine again. Each set of coords is about 100 value pairs for ._x and ._y

      The issue is that on long runs, more than 5 or 6 sets of coordinates, with low millisecond values in setInterval (say 10 - 15) the CPU loading gets dramitically higher as the sequence progresses, effectively throttling the animation down once the loading on the CPU gets above about 80%

      To my mind - the effort to draw the 8th shape in a sequence should be the same as that required to draw the first - but this is clearly not what is happening in practice - I have also checked CPU loading with the higher millisecond values set by the slower speeds - and here too CPU loading increases, but not as dramatically.

      Memory useage does not increase just CPU so clearly there are thing being left running - any pointers to where I should look to solve this, would be very gratefully received...

      TIA

      Nigel
        • 1. Re: setInterval - CPU loading issue
          kglad Adobe Community Professional & MVP
          this is a problem with the flash drawing api and i know no work-around. i ran into this problem during my work graphing the mandelbrot set ( http://www.gladstien.com/mb/mandelbrot.html ).

          you can see the graph is drawn using horizontal lines from top to bottom. the lines at the bottom always take a good deal longer to be rendered than the lines at the top.

          cpu utilization is not the cause of the problem, however. i believe the flash player is getting bogged down.

          in its simplest incarnation the following code displays the issue:

          • 2. Re: setInterval - CPU loading issue
            NoNameNoPackDrill Level 1
            eeeer thanks - well thanks for the reply - but the content of that reply is very worrying for my project.

            I will have to investigate some kind of workaround - perhaps using multiple , individual movie clips, rather than one large one for the drawing will help.

            I sense a long weekend...
            • 3. Re: setInterval - CPU loading issue
              Level 7
              > perhaps using multiple ,
              > individual movie clips, rather than one large one for the drawing will
              help.

              Well, give it a try, but I'd be very surprised if it helped. In the days
              before the drawing API was available, you could fake it by attaching
              multiple clips, rotating and scaling, but would run into the exact same
              problem - the more clips you attach, the slower it will get...good luck -
              post back and let us know how you go!

              P

              --
              -------------------------------
              Remove '_spamkiller_' to mail
              -------------------------------


              • 4. Re: setInterval - CPU loading issue
                kglad Adobe Community Professional & MVP
                i tried many work-arounds for this problem including

                1. creating a movieclip for the first line, when the line is completed enable the movieclip's cacheAsBitmap property, create a new line and draw the 2nd line, enable its cacheAsBitmap property etc.

                2. i eliminated the drawing api and used the bitmap objects copyPixels() method

                3. i isolated the drawing portion of the code to an external swf that i reloaded whenever line drawing slowed to beyond a calculated range saving the drawn portion to a bitmap that could be augmented with subsequent loads.

                4. a variety of tweaks on all of the above.

                in the end, i was able to increase the speed of rendering by a factor of 10 to 20. that was a significant benefit but i needed another factor of 10 to really make the mandelbrot drawer more enjoyable. and i believe that benefit was realized by using a tweak of 1. instead of using a separate movieclip for each line, i only created another movieclip when a line rendering slowed beyond some fraction of the previous line.
                • 5. Re: setInterval - CPU loading issue
                  NoNameNoPackDrill Level 1
                  Guys - I just put a clooge into my code to break up the drawing into 10 movieclips instead of one large one - easy coz I already had movieclips on the stage in the right places- and on my 5 year old DELL the animation now runs at constant speed and never gets above 8% CPU load!

                  So I call that fixed - well it will be when I sort out all the other consiquences of the change - might even be able to get out into the garden by Sunday now!

                  Thanks for poking me in the right direction

                  Nigel
                  • 6. Re: setInterval - CPU loading issue
                    kglad Adobe Community Professional & MVP
                    you're welcome.
                    • 7. Re: setInterval - CPU loading issue
                      Level 7
                      Well, ther you go then! :) Glad you sorted it out.

                      --
                      -------------------------------
                      Remove '_spamkiller_' to mail
                      -------------------------------