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 Responses to “TAAS progress”


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

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

  • 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

  • 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.

  • 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.

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

  • 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

  • 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 :)

  • 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.

  • 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)

  • 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.

  • 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.

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

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

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

  • 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 ;)

  • 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

  • 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 :)

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

  • 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.

  • 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.

  • 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 :)

  • 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 ?

  • 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.

  • 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.

Leave a Reply