November 5th, 2008 Posted in AS3, General | 1 Comment »
It’s very tempting to think performance doesn’t matter. After all, not all of us are writing code that goes into millions of iterations per frame or that performs complex algorithms. Even with quite large RIAs it’s possible you’ll only deal with very small data sets and only loop over a handfull of items per array. So for most of us it’s easy to think “well that works” and move on. It is often the case even when you’ve spent time implementing the sweetest architecture or the latest design pattern not to revisit the guts of what you’ve written.
Wherever I work I like to encourage people to think more about performance. Even when the program is quite small, thinking about the finer details of how your code executes can help to understand the enviroment your code runs in and ultimately the machine itself (this is more and more important for ActionScript developers. As the language improves so the responsibility of the developer to understand what happens under the hood increases too). If you haven’t yet built a large application then you very likely will in the future so equiping yourself with the understanding now will stand you in good stead for when the time does come.
If you’re anything like me then planning for the future is often not enough motivation to do something now, especially when you have deadlines and managers hanging over you and the like. So perhaps you need another motivation to think about the performance of your code.
Enter the “Enviroment” (I’m tryng not to cringe as I write this, it IS an important issue after all).
It’s not just about how your apps’ performance impacts the user while it runs, it’s also about it’s reach. By reach I refer to how many people are going to find and use your program. Even if it’s a small frame script on a flash advert, that advert could very well be seen and run by millions of people. All of a sudden 10 iterations over a loop become 10 million iterations. One millisecond of CPU time becomes several minutes. Eco Programming is about getting the best performance even when the impact on the user is negligible in the hope that the overall efficiency might have a significant combined effect.
The energy consumption of CPU’s has become more important in recent months. CPU benchmarking laboritories are staring to pay attention to how energy efficient processors are. The image below is taken from a recent report which benchmarks CPUs for various things, but includes wattage at 100% load.

Though it’s not clear how long the tests were run for, it’s not difficult to imagine how by reducing the overall CPU time of your app by as little as millisecond you can begin to save several Watts over the full reach of the product. If we all were to do this then we might make a significant impact on power consumption.
If saving the world isnt enough motivation to get performance tweaking, then maybe just that its good fun is enough for you :). Here are a few links to get you started on improving the performance of your programs:
http://osflash.org/as3_speed_optimizations
http://mikegrundvig.blogspot.com/2007/05/as3-is-fast.html
http://gamedevjuice.wordpress.com/2008/02/15/seven-tips-about-performance-optimization-in-actionscript-3/
http://www.danielhai.com/blog/?p=55
There are loads more… get googling!