November 22, 2010

I’ve been working on optimizing some javascript code these days and I came across a technique for optimizing long loops called Duff’s Device or Loop Unwinding which seems pretty well known in the javascript world but I haven’t seen anyone use it in actionscript code.

The basic idea is that there is a small overhead associated with executing the loop body, so if we unfold the loop in a way that it does the work of 8 iterations in 1 iteration, we can save some time. My tests show that in long enough loops this technique can give us 8x to 10x performance gain.

Here are the results of my tests using Grant Skinner’s performance test harness

Here are the actual test cases .. read more

May 29, 2010

I haven’t talked much about our startup project factors on this blog yet, but you will hear more and more about it from me over the coming weeks. Today, we’re open sourcing a very small but quite interesting part of the factors web client code. The client is built mostly in AS3 using an in house framework we call crayons. Crayons provides an application architecture as well as a library of user interface components along with a component architecture, you could think of it as a mixture of functionality provided by flex framework and cairngorm, but several times lighter since it only implements functionality we need for factors and doesn’t try to be too generic.

Among other things Crayons has a built in data binding framework which we’re open sourcing today. Data binding in crayons in based on Signals where an object dispatches a specialized ChangeSignal whenever a bindable property changes, for example the setter of a bindable property data in SomeModel object would look like this … read more

April 2, 2010

Update: Troy Gilbert suggested a much better solution for this in the comments below that uses -frame compiler option over the [Frame] metadata tag, I suggest you use his approach since it stops the compiler from bundling in Flex framework specific code like IFlexModuleFactory that you don’t really need.

Update: Troy further improved his class here

***

Today, I needed to create a preloader for a pure AS3 application compiled with mxmlc. I couldn’t find much documentation on the topic but this post by Keith Peters describes the solution in good detail, except his post is some what old and the code there doesn’t work with the latest compiler..

As Keith describes, the first thing you need to do to implement a preloader is move your application to the second frame of the movie, this is done by adding a [Frame] metadata tag above your document class and providing it with a factory class that will initialize your application, in case of Flex this factory is mx.core.SystemManager .. read more

March 17, 2010

SWF Machine is an Erlang program I’ve been writing, to generate SWF files from Erlang. This program takes a custom instruction set as input and generates SWF binary instructions, which once saved in an SWF file can be run in the Flash Player, here’s a quick demo of SWFMachine in action …

A similar attempt by Takashi Yamamiya and the eswf library on google code were quite helpful in getting me started, so thanks to them for sharing.

January 24, 2010

I had the opportunity to present a 4.5 hr lecture on Building Rich Internet Applications at ACM’s Compute 2010 today. We started out by defining what an RIA is and exploring the various RIA platforms available, we then further explored the Flash Platform in more detail, wrote some experimental code to understand the internals of Flash Player, looked at Flex 4 and its various new features and also spent some time understanding the Flex Component Lifecycle

Here’s the slide deck from beginning of the lecture which tries to define what an RIA is and explores the architecture a typical RIA platform …