Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.


AS3: Bitwise operators can now be faster

Posted February 19, 2007 by senocular

There are certain tricks you can pull in some languages to get a small boost in math performance by using bitwise operators in place of some mathematical operators. For example, instead of multiplying a number by 2 (*2) you can shift it by 1 (<< 1).

This kind of optimization had no effect in ActionScript 2 because all number values were treated as the Number type, or a float, and those two operations performed the same. Now, with ActionScript 3, when using values of the type int or uint, you can get better performance out of bitwise operators than you can normal math operators (ints and uints are actually treated as Number types for normal math operations). This means if you're still looking for that extra bit of speed, you might be able to use bitwise operations on your ints to get it.