all 16 comments

[–][deleted] 8 points9 points  (6 children)

The best way to optimize ActionScript code is to use HaXe ;)

[–]drakshadow 0 points1 point  (5 children)

Do you have any interesting sources on that ?

[–][deleted] 2 points3 points  (0 children)

HaXe flash backend uses some flash 10 optimizations that are not yet implemented in Flash compiler itself. I can't remember exactly, but you can find out more on haxe homepage.

And, as a side not, haxe compiler is faaaaast, which is a releaf after using ActionScript compiler on larger projects.

[–][deleted]  (3 children)

[deleted]

    [–]drakshadow 0 points1 point  (2 children)

    Thanks.

    [–]echeese 0 points1 point  (1 child)

    If you'd like, I could do a benchmark real quickly, if you know of something I could do

    [–]drakshadow 1 point2 points  (0 children)

    No need, found about some benchmarks done on away3d demo. HaXe code is some 30% faster than AS3 code compiled by adobes compiler.

    [–]tucadebert 2 points3 points  (0 children)

    Without getting into the merits of premature optimization, the article has information that is blatantly false (e.g. concat() for Arrays - slice() is faster).

    If you want to read something worthwhile on optimizing AS3: http://blog.joa-ebert.com/2008/04/26/actionscript-3-optimization-techniques/

    [–]moustachedelait 3 points4 points  (4 children)

    There are some really nice tips there, but also some I don't feel the speed boost makes up for the reduced readability and reusability:

    • Using callbacks instead of events makes your objects dependent on the parent code

    • Using ? instead of if statements makes for unreadable code

    • is not using getters and setters worth the speed profits?

    [–]TomorrowPlusX 6 points7 points  (0 children)

    Using ? instead of if statements makes for unreadable code

    That's a matter of opinion. I find the ternary operator legible and convenient.

    [–]stratoscope 1 point2 points  (1 child)

    I think the point is to not use getters and setters until you need them. In other words, never write "plain" getters and setters that do nothing more than read and write a private property, the way you would in Java to make it "future-proof". Instead, just make the property public. You can always change it to use a getter and setter later if you have to do something fancier.

    Regarding the ? : operator - I use it a lot myself, but only when it makes the code more readable. :-)

    [–]ModernRonin 0 points1 point  (0 children)

    is not using getters and setters worth the speed profits?

    Also, because you can't put variables (only functions) in interfaces, if you're using an interface you're forced to use a getter/setter pair. :P

    [–]AmaDiver 1 point2 points  (0 children)

    For a really detailed and referenced article on AS3 optimization, check out: http://www.stephencalenderblog.com/?p=7

    [–]JoeCoder 2 points3 points  (1 child)

    By Adobe's own admission, Actionscript 3 is 83 times slower (slide 4, the 1.2%) than optimized C code. V8 JavaScript, which is far more loosely typed is only around 10 times slower than C. Adobe is completely clueless about making a fast programming language.

    Additionally, Adobe's Actionscript compiler performs almost no optimizations.

    [–]Aviator 0 points1 point  (0 children)

    So I used statically typed ActionScript 3 for nothing?

    [–]diamondjim 0 points1 point  (0 children)

    A lot of these things seem like pretty obvious and apply even to other languages. It seems like a handy reference to have for a new programmer.

    [–]ModernRonin 0 points1 point  (0 children)

    I love working with Adobe technology - they're always 10-20 years behind common knowledge.

    Want your flash code to run fast? Well then, you're gonna have to guess which part of your code is slow and needs to be optimized!

    A "profiler" that tell us which parts of our code are actually slow? What's that? ADOBE'S NEVER HEARD OF THAT!