Search code examples
actionscript-3optimization

Flash optimisation confusion


I'm new to Actionscript (v3), 20 years C++ though, and I'm just trying to get my head around some of the performance caveats I'm reading.

I checked out this site:

http://www.nbilyk.com/optimizing-actionscript-3

and was scared to death of the 'code' section saying that Actionscript has to do a dynamic lookup when trying find static methods in a package. The point being that it is inefficient to put your util-type functions (typically math functions) in their own package as static functions, because it has to lookup the namespace and method dynamically each time you call it.

Is this true? It's just so not what I expected, coming from C++, and it really changes how I structure my code and libraries. I wonder if it's better to have a singleton util library that is new()'d once, containing the methods as normal public methods, than have them static in another package.

Are there any other obvious gotchas like this?

Cheers,

Shane


Solution

  • Yes its true. Calling static functions from outside the class is slow. I recently tested this for myself, over 10,000 iterations it was 220ms for static vs 160ms for calling the function on an instance.

    Other tips would be to avoid the Adobe compiler. I have recently started using Haxe which converts to LLVM and then to ABC code (actionscript byte code). There are some hidden opcodes for dealing with memory that Haxe takes advantage of (same as Alchemy).

    Speaking of alchemy it will compile C++ --> LLVM --> ABC. Might be useful for you if you have lots of c++ libraries. (someone ported Doom, Hexen, and Heritic over to Flash this way)

    EDIT: for anything performance related http://lab.polygonal.de/ and http://blog.joa-ebert.com are good places to start.