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

Original Article

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

Original Article

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()

Original Article

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

Original Article

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

Original Article

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!