Flash Player 10.1 Performance: Part 3
Today’s article is the third in a series re-testing previous performance articles with Flash Player 10.1 and comparing the results to those that I got with Flash Player 10.0. If you haven’t already read the first or second part of the series, you should check them out first. If you have, read on for more performance comparisons!
Introduction
This part’s performance methodology will be the same as last time and in the original, so let’s delve straight into the comparisons.
Beware of Getters and Setters
Sprite | Point | MySprite | MyPoint | |
---|---|---|---|---|
Flash Player 10.0 | 153 | 35 | 25 | 62 |
Flash Player 10.1 | 190 | 28 | 27 | 80 |
There are no major changes to the numbers here, but we can at least confirm that not much has changed. It’s still a good idea to cache X and Y values for Sprites if you use the getters a lot. Unfortunately, calling a getter function instead of accessing a public variable is now a 3x slowdown instead of 2x. This can be a real bummer for high-performing class design.
Var Args Is Slow
Pre-Allocated Array | Dynamically-Allocated Array | Var Args | |
---|---|---|---|
Flash Player 10.0 | 10 | 255 | 262 |
Flash Player 10.1 | 12 | 117 | 120 |
While the pre-allocated array version is negligibly slower, there has been a major speedup in the other versions! Both versions are now 2x faster in Player 10.1 than they were in Player 10.0, presumably due to speedups in memory allocation. This is a really big win for var arg functions, but an even bigger win for general object allocation. This serves as good confirmation of the results from part one’s free list test.
Faster isNaN()
Environment | isNaN(33) | isNaN(NaN) | myIsNaN(33) | myIsNaN(NaN) | inline for 33 | inline for NaN |
---|---|---|---|---|---|---|
Flash Player 10.0 | 48 | 39 | 9 | 7 | 4 | 4 |
Flash Player 10.1 | 26 | 24 | 13 | 21 | 3 | 3 |
My custom implementation of isNaN suffers a setback in Flash Player 10.1, which is a good thing. After all, you shouldn’t have to re-implement such a basic function in the first place. When myIsNaN is called with a non-NaN value, it is still 2x faster than isNaN. However, when it is called with NaN there is no longer any speedup. When inlining the check for NaN the speedup returns and both NaN and non-NaN values return their usual 10x speedup. So the advice from Player 10.0 remains: for ultimate speed you should inline your isNaN calls.
Inlining Math Functions
Function | Player 10.0 | Player 10.1 |
---|---|---|
abs | 16 inline, 40 Math | 14 inline, 23 Math |
ceil | 15 inline, 55 Math | 22 inline, 30 Math |
floor | 15 inline, 57 Math | 22 inline, 30 Math |
max | 481 inline, 122 Math | 291 inline, 112 Math |
min | 478 inline, 133 Math | 299 inline, 103 Math |
max2 | 14 inline, 43 Math | 27 inline, 34 Math |
min2 | 15 inline, 35 Math | 24 inline, 27 Math |
Universally, every Math function tested has been sped up in Flash Player 10.1, which is great news! After all, these are the functions most of us use and, like my custom isNaN above, we shouldn’t have to write in the first place. But should we still use custom versions instead of the ones that come with the Math class? For the best performance, it’s still a good idea to inline all of them except min and max. Even so, consider using an inlined version of min2 and max2 when, as is most usual, you only have two arguments to pass as these will blow away their var args equivalents by at least 4x.
Map Performance
Class | Player 10.0 | Player 10.1 |
---|---|---|
Array | 37 hit, 194 miss | 58 hit, 238 miss |
Vector Dynamic | 25 hit, 12313 miss | 53 hit, 8841 miss |
Vector Fixed | 25 hit, 12234 miss | 49 hit, 8796 miss |
Object | 280 hit, 316 miss | 155 hit, 205 miss |
Dictionary Strong | 296 hit, 399 miss | 166 hit, 272 miss |
Dictionary Weak | 293 hit, 400 miss | 169 hit, 270 miss |
BitmapData no alpha, getPixel | 53 hit, 60 miss | 99 hit, 90 miss |
BitmapData no alpha, getPixel32 | 54 hit, 61 miss | 101 hit, 89 miss |
BitmapData alpha, getPixel | 67 hit, 58 miss | 109 hit, 87 miss |
BitmapData alpha, getPixel32 | 68 hit, 59 miss | 106 hit, 84 miss |
ByteArray | 48 hit, 44 miss | 86 hit, 63 miss |
Arrays are about 20% slower in Flash Player 10.1, which is a letdown since they are so commonly used. An even greater letdown is that Vector hits are about twice as slow, which is not nearly as important as the 25% speedup in Vector misses. Since Vector is the main alternative to Array and supposedly the faster version, this leaves the AS3 programmer in a bit of a pickle. Still, Vectors do maintain the performance crown over Arrays… so long as you rarely miss. Objects and Dictionaries are now nearly twice as fast as they were in Player 10.0, which should come as a welcome surprise after the bad Array and Vector news. Sadly though, all forms of BitmapData and ByteArray reads have been slowed down in Player 10.1 by at least a 50%. Bummer.
More To Come
I’ve still got 17 more performance-related articles to review and potentially add to this series, so stay tuned for many more performance updates for Flash Player 10.1!
#1 by Kevin Newman on July 21st, 2010 ·
I’m curious if you’ve noticed a difference in these number between platforms and browsers. For example, do you get a smaller gulf in BitmapData performance in the ActiveX (IE) version vs. the Plugin version running in Firefox (on Windows)?
I’ve noticed also that Firefox with 10.1 seems to run more quickly for about a second or so, then cuts down performance on mildly intensive applications. On my PCs (but not mac) I see that in this example (with the release player, this is insanely slow with the content debugger): http://www.unfocus.com/2010/06/29/the-bunny-video-eplodes-explodes/
#2 by jackson on July 21st, 2010 ·
Most of my performance tests are done on both Windows XP and Mac OS X to catch these sorts of cross-platform performance issues, which do occur from time to time. For this series of articles though, the sheer amount of testing required to include Mac OS X was simply too much. If any performance test is of particularly high importance to you, I’d recommend grabbing the source from the “Original Article” link and seeing what results you get on Mac OS X as you’ll get the numbers much faster than I’ll get around to posting them, if I ever do. The same goes for the plugin version versus the ActiveX version, though I haven’t seen any strong performance differences between them when running just intensive AS3. Certainly there are differences when graphics, input, sound, networking, and so forth come into play. Have you noticed any differences between the plugin and ActiveX versions for pure AS3? If so, I’d be quite interested in taking a deeper look.