TAAS progress

I have developed some other optimizations during the past couple of days. Including strength reduction and optimizing tail recursive calls.

Strength reduction can already handle about 55 different cases at the moment. For instance it will convert code like if( x - 1 == 0 ) into if( x == 1 ). But it will also remove expressions that other optimizations could introduce. x + 0 is something that might occur during inline expansion. Or x + Number.NaN for example.

But I really like the tail recursive optimizations. TAAS can detect if a method needs to call itself or not. Take this code for example:

private function sum( i: int, value: int ): int
{
	if( i == 0 )
	{
		return value;
	}

	return sum( i - 1, value + i );
}

You see that the last statement sum( i - 1, value + i ) is tail recursive. This means we can replace the recursive call to sum() with a jump to the beginning of the method after changing the method parameters. The sum() method becomes converted to something like a simple while loop. This means also that one could have written code like this in the first place since this optimization applies only to methods that do not have to be recursive after all.

Knock yourself out with some examples:

25 Comments

  1. Posted Sep 7, 2009 at 5:00 pm | Permalink

    Looking good. Any chance of the sources, and a way to compile the TAAS/Apparat versions ?

  2. Posted Sep 7, 2009 at 5:07 pm | Permalink

    Yes, I will commit all test sources later this evening or tomorrow with some instructions on how to use the TaasCompiler.

  3. Posted Sep 7, 2009 at 5:14 pm | Permalink

    Awesome work continuously Joa :)

    Could you perhaps post an example where you use an exisiting library such as PaperVison3D or Away3D, or whatever, to show how much of a difference it makes to have TAAS optimize those kinds of swf’s.
    I guess people’d be interested to see, TAAS is a potential gamechanger (pun intended) for Flash gaming I’d imagine. Or am I drawing the wrong conclusions here ?

    cheers,

    Roland

  4. Posted Sep 7, 2009 at 5:29 pm | Permalink

    Roland: I would love to show such an example but in order to do that I have to get rid of all the teething troubles. Right now I could not compile a big project like PV3D because something would break and I could never figure out where.

    Therefore I test step by step and once I am done I will definitly target a more interesting example.

  5. valyard
    Posted Sep 7, 2009 at 6:00 pm | Permalink

    great work!
    right now I’m working with Erlang where most of the loops are done with tail recursion which is extremely fast. Nice to see such optimization in flash.

  6. Posted Sep 7, 2009 at 6:18 pm | Permalink

    Really impressive Joa! The results are shockingly good. Can’t wait to se ewhere this goes.

  7. Cabby
    Posted Sep 7, 2009 at 7:33 pm | Permalink

    Awesome as usual.

    What references do you use for your work? I would love to see where you get your ideas, inspirations and knowledge from, even though I will not be able to understand most of the stuff, anyway :p

  8. Posted Sep 7, 2009 at 7:55 pm | Permalink

    Those are great resources:
    http://www.nullstone.com/htmls/category.htm
    http://en.wikipedia.org/wiki/Compiler_optimization

    Once you know the keyword, Google is your friend as always :)

  9. Posted Sep 7, 2009 at 8:05 pm | Permalink

    Pretty impressive. Since your last post I wanted to test your project on some of my works like this http://wonderwhy-er.deviantart.com/art/Collision-Sparks-99408656 or this http://wonderwhy-er.deviantart.com/art/A-W-C-A-F-I-T-135334558 to see how much difference in performance I can get as I use a lot of my own code there and probably there is much to optimize there. Will wait for your new commit with those new optimizations and will try to test it + post results here.

  10. edgardz
    Posted Sep 8, 2009 at 10:23 pm | Permalink

    Hi, i tried TaasCompilerTests.java pointing test00 to my swf. After 56s another swf was generated, but i cant run it. Probrably im forgeting something… But congrats, your results are amazing! (sorry about my english)

  11. Posted Sep 9, 2009 at 12:10 am | Permalink

    edgardz: It could be possible that your SWF resulted in a runtime error. Did you see something show up?

    Besides, if you want to try it out, I have added a new test and all my AS3 sources that definitly work. Although: a lot is still in development, so stuff can break.

  12. edgardz
    Posted Sep 10, 2009 at 3:48 pm | Permalink

    Of course!
    I saw a LOT text appearing on the console. I can send it to you if help you somehow. My msn is the same as my e-mail.

    Again, great work! It will help the entire flash development community.

  13. Posted Sep 13, 2009 at 9:20 am | Permalink

    Hm… The ‘Tail recursion’ samples eat about 2 GB of my RAM [!]

  14. Posted Sep 22, 2009 at 10:32 pm | Permalink

    This is fantastic – you’re not by any chance presenting at MAX are you? I’d love to see a presentation on this.

  15. Posted Sep 23, 2009 at 12:48 am | Permalink

    Actually, I am at the MAX Unconference thanks to Influxis :)

  16. oli
    Posted Oct 1, 2009 at 12:14 am | Permalink

    exiting stuff!
    every math teacher would be jealous as hell, if he could see the reactions, you provoked, at the conference …

    so anyway, what is actually not yet possible with TAAS?
    In other words, what is keeping us from using it on production-level right now?

    I browsed through the TODO-List on Apparats googlecode page… but it might as well be written in Japanese as far as I understand ;)

    keep it up and freundliche gruesse ;)

  17. nada
    Posted Oct 4, 2009 at 1:24 pm | Permalink

    your work really boosts urge do tryout something new again!

    here may not be the right place to ask such things but i am asking myself: sucessfully compiled ap.core + ap.test.as3, did run the unit test, got new swf’s in the asset folder, when diffing’em (test03) i can see inlining has happended, but on my mac, both swfs running exactly at the same speed (∼58fps), not like your wonderful fotb example…
    is this fp on mac? or just me stupid?

    very cool the fotb session is online!

    grx

  18. Posted Oct 6, 2009 at 12:57 am | Permalink

    That is the Flash Player on the MAC. It will not run faster than 60fps. But have a look at the milliseconds in the stats window :)

  19. Valentin
    Posted Oct 15, 2009 at 7:15 am | Permalink

    Is there a compiled version I could test?
    Can’t compile the source on Mac, I guess I don’t have 1.6 runtime.

  20. Posted Oct 15, 2009 at 6:16 pm | Permalink

    If you can not compile it because you do not have Java 1.6 you will not be able to run it.

    There is also no compiled version available since this is a work in progress. Compiling and running the compiler is not so easy at the moment.

  21. oli
    Posted Oct 17, 2009 at 12:25 am | Permalink

    there may be no compiled version of the compiler, but with joas taas framework it is really easy to write a little tool yourself and add it to the collection of tdsi, reducer and dump.
    its basically just a matter copy and paste, since the most important stuff is already written by joa.
    i could make my version of such a tool publicly available ,if someone is interested.

    oli.

  22. Posted Oct 18, 2009 at 2:38 pm | Permalink

    oli: I guess this does not make sense at the moment. TAAS is not complete and people would just complain that it does not work. Just take a look at all the TODO()s in TaasBuilder :)

  23. oli
    Posted Oct 18, 2009 at 11:08 pm | Permalink

    yes , i noticed :)
    the TODOS answered my first question ;)
    it’s still fun to play around with it though.

    by the way, if you use the ‘builtin.abc’ from the latest tamarin-redux , TAAS doesn’t read it in correctly.
    is this expected ?

  24. Posted Oct 19, 2009 at 12:47 pm | Permalink

    No, not at all. But I think I saw somewhere a different specification for *.abc files so maybe that is the reason (and that would be expected). I will have to look into that.

  25. Posted Apr 20, 2010 at 1:07 am | Permalink

    Pretty impressive. Since your last post I wanted to test your project on some of my works like this http://wonderwhy-er.deviantart.com/art/Collision-Sparks-99408656 or this http://wonderwhy-er.deviantart.com/art/A-W-C-A-F-I-T-135334558 to see how much difference in performance I can get as I use a lot of my own code there and probably there is much to optimize there. Will wait for your new commit with those new optimizations and will try to test it + post results here.

One Trackback

  1. [...] This post was mentioned on Twitter by David Lenaerts. David Lenaerts said: Still loving reading up on the progress, great job! RT @joa: #TAAS progress http://bit.ly/ZBSIp [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*