Friday 20 January 2012

Fast path member access

I noted on Wednesday that accessing members by repeatedly doing a lookup in a Vector is slower than doing that lookup once. But it was slower even than I expected. The code was doing the lookup eight times more than necessary, but was over twelve times slower (i.e. it took over twelve times as long). So I forked the code and re-wrote the tests to find out what was going on. The results of this are especially interesting.

Thursday 19 January 2012

Wednesday 18 January 2012

Dereferencing array members

The title refers to code like this


iSum += aData[iIndex];


Looking up in an Array (or Vector) requires the code to find the address of the object or value requested then retrieve whatever's at that address. It might also check whether it exists, and whether it is in range (and if not whether it should grow the Array or Vector to accomodate it).

Tuesday 17 January 2012

Accessing members by name

One sometimes misunderstood feature of ActionScript is that as well as accessing members of a class directly and using accessors it's possible to do so using the name of the member, passed as a String to the class. Misunderstood as there is a right way to use this and a wrong way to use this. And the wrong way is incredibly slow, so much so it should be avoided at all times.

Monday 16 January 2012

More on angles

In a recent post I asserted that angles are rarely needed for game mathematics. There are a few exceptions but far fewer than many people realise. But it's easy to doubt this assertion. What is there theory behind it? Is there a way to check when angles can be avoided? Not only can both questions be answered but the answer to them is the same.