Today, I happened to have Activity Monitor open while I was working on AgileAgenda and noticed something peculiar. It was sucking up 200% of CPU time (multiple cores…)
So I fired up the application in the Flex profiler. Let it sit for a minute, clicked the “Reset Performance Data” button, waited another few seconds, and then clicked the “Capture Performance Data” button. The result was odd.
Nothing was actually in code I could touch and didn’t explain why it was happening. There had to be something going on to peg out the CPU like that. So I hit up the Flex preferences panel and found something I had forgotten about.
By default, the profiler excludes a whole bunch of flex and flash related classes from the profiler. So I removed those exclusions and unchecked the box. Went back to my profile window and low and behold, this is what I saw:
So now I had an idea of what was happening. It looks like that indeterminate progress bar (which wasn’t on the screen anymore by that point) was sucking up some render time.
So I peeked at the ProgressBar flex code. They’ve got a timer in there that gets started, and is stopped when the progress bar is set to invisible. But that doesn’t end up accounting for cases where we just bump to a different parent object in a view stack. So that timer sits there, happily spinning and consuming resources.
I added some code in to manually set the visiblity of the 2 indeterminate progress bars I had and ran. Bamn, success.
So I learned (or re-learned?) two things today.
- When profiling, if you don’t see anything happening check your filters.
- Be very careful with indeterminate progress bars in flex.
Note: I got similar results both in the debugger (ADL) and when running the application stand-alone as a bundled application.






So 2 spinning timers knocked the cpu from 4% to 216%? surely not?
Afraid so.
Now it wasn’t just the fact that 2 timers were going, it was the fact that the two progress bars were constantly animating. I’m assuming it’s because of a deeply nested display list and either the flex layout code was constantly running, or the Flash rendering code was going crazy. After manually setting the visibility on those two progress bars everything was fine (and that being the only change). But once solving the problem I didn’t investigate the why any further why it was happening.
I came upon the indeterminate progress bar issue a different way one time. I happened to be running an app and just to play around, turned on “Show Redraw Regions” and in the middle of the app there’s this moving red rectangle. I realized it was my progress bar still redrawing itself. This was back in the Flex 2 days without the Profiler.
I had an almost identical experience with a spinner-style progress component I found online. The assumption was that Flash would stop trying to render an item no longer on screen; that assumption ended up being very wrong.
- max