Function calls in Flash are notoriously slow. Recursive algorithms require lots of function calls by definition. So are iterative versions faster? Today’s article explores whether or not it’s worth converting your recursive algorithm into an iterative one.
Int Keys: Object vs. Dictionary vs. Array vs. Vector
Given that Object and Dictionary can have int keys and that int keys are faster than String keys, a natural performance test follows: which class is fastest at reading from and writing to those int keys? Is there a difference between the four Vector classes? Today’s article performs just that test and comes up with the answers.
String Keys vs. Int Keys
Now that we know you can use int keys with Object, it’s time to test whether or not this is any faster than String keys. Today’s article does just that and also tests int and String keys with Dictionary.
Using Non-String Keys with Object
Pop quiz: what’s the difference between an Object and a Dictionary? If you said “Dictionary can have non-String keys”, you bought into a common myth. Today’s article shows the cases where the lowly Object class will use non-String keys whether you like it or not. Read on for the details.
5x Faster For-In Loops
I’ve recently been notified of a way to dramatically speed up for-in loops. I’ve tested this method out and indeed there is a 5x speedup. Employing the technique is also really easy. Unfortunately, the speedup is sometimes an illusion. Read on to learn a little more about for-in loops and how you could potentially speed yours up by 5x.
XMLDocument: The Faster Legacy XML Option
Sometimes the old, legacy option is faster than the new one you’re supposed to use. That happens to be the case with XML in Flash: XMLDocument is quicker than XML. Today’s article tests its performance to figure out just how much faster it is and if it can keep up with plain Object and typed class instances.
XML E4X Expression Performance
If you deal with XML documents, you probably appreciate AS3’s support for the E4X operators. These make it really easy to access the XML class like any old object with the .x (dot) operator as well as XML-specific operators like ..x for descendants and @x for attributes. Even fancier, there’s support for arbitrary expressions like .(@id == "123"). With all this convenience we should wonder- how slow are the E4X expressions?
XML E4X Operators vs. XML Class Methods
Take Advantage of CPU Caching
Your computer has RAM, but it also has much faster forms of memory. If you want your app to run quickly, you need to be aware of these other memories. Today’s article discusses them and shows two AS3 examples that, even with such a high level language, you can still take advantage of them.
Easily Create Power-of-Two Textures
In almost all circumstances, Stage3D requires you to provide textures with power-of-two dimensions. This is often inconvenient as most images are not already sized that way. Today’s article provides a simple class to easily build a texture with power-of-two dimensions. An example app is also provided.