PDA

View Full Version : Performance in Flash


monsoon
06-14-2007, 05:18 AM
Hi,

I've been scouring the web looking for concrete descriptions of how different content affects performance (CPU load) in flash. I'm interested solely in the visual side, i'm fine for optimising code but would love to know if anyone has any idea on the following:

*does CPU load get affected depending on how you stack vectors and bitmaps over and under each other and in multiples, animated and still? I've noticed having a PNG background is generally a lot better than vector, which makes sense seeing as it only needs to render once but there are a lot of permutations to test and surely someone has some knowledge already?

do animated clips made up of PNGs perform better than vector ones. I know overly complex vectors are bad news but for simple stuff?

what can be masked fine and what takes a huge speed hit? thinking here of PNG (with and without alpha), vector, video, JPG, both still and animated and with different permutations of background/stacking.

Also, I noticed there's more interest in performance with Flex than Flash, what with the limited medium but does that advice go for standard Flash too?

for my part, I know that the bigger the redraw region the bigger the CPU hit and the same with higher frame rates. over to you...

monsoon
06-15-2007, 12:19 AM
Hi again,

So I came up with these guidelines, if anyone can add more or correct me, that'd be fabulous:

The redraw region
Ie, how much of the screen has changed since the previous frame? Animating in the bottom half of the screen incurs almost half as much CPU load as animating in the top and bottom. Naturally, this also means that the larger your stage, the larger the CPU load.

The frame rate
The higher the frame rate the more work the CPU has to do.

The _quality setting
Using a lower quality setting reduces the work flash has to do.

Complex animated vectors
Whilst vector graphics can be smaller in file size than bitmaps Flash has to do the maths for them on every frame. We can toggle Flash 8’s marvelous cacheAsBitmap setting to convert static vectors to bitmap once they are first drawn (which is a nice way to take advantage of the lower file size of a vector graphic without incurring sustained overhead) but not if they are animated.
The same goes for gradients and filters in vector graphics, it’s all more work for Flash.

Animating over a vector
Flash has to do the maths to show a vector and if there’s something else on top that’s even more work for it to do.

Masks
A lot of noise has been made about the horror of masks, they’re not all bad, you just have to be careful with them. Using a mask on a static item, especially a bitmap, adds a little more CPU load but not much. Where masks do most of their evil is on any kind of animated clip, especially vector (using a rectangular mask over an _x/_y tweening bitmap is fine). Use visibility and clever layering to hide edges if you must mask an animation.

Scaling
Scaling is bad, and usually unnecessary. It’s more work for the CPU. If you must scale a static graphic you can cheat with good old cacheAsBitmap but scaling vector animations should be kept to a minimum. One nice way to cheat Flash is to load in a small jpeg, keeping file size low, then scaling it once in flash and setting it’s cacheAsBitmap to true. Sneaky.

Bit depth
Bit depth is generally more of an issue for file size than CPU. The higher the bit depth the more CPU load goes up but only marginally. See below for alpha channels.

Alpha channels
PNGs with alpha channels will generally perform better than vectors all the time so if you must use alpha then do it but bear in mind that Flash now has to work out what to show behind the graphic and so the more alpha channeled areas there are on the screen the bigger the CPU load. A little use is fine but try not to get too alpha happy. If you need an L-shape you can cheat by using two rectangular PNGs.

JPG vs PNG
It all depends on your graphic, use whatever is most suitable for file size and you won’t go far wrong.

Stacking
I’m still a little vague on this one but my tests threw up a surprising result whereby stacking (partly overlapping) more and more animated bitmaps seemed to add more load to the CPU than doing the same with animated vectors. Hmm..