Adobe Alchemy

Adobe put the Alchemy project (formerly FlACC) on the labs site today: http://labs.adobe.com/technologies/alchemy/

So is anyone up to getting Box2D working with it? I would love to see what kind of performance gains are to be had.
Alchemy is basically an LLVM target, so I'm not sure that we can expect major speed gains (it essentially interprets the machine code in the AVM2, if I recall the details correctly, so it's not as if we're really running native code).

Still, it would be interesting to see how Box2d performs when translated in this manner. Box2d would be a perfect example library for this, since it is mostly independent of anything OS or hardware specific.
Well, if we are to believe Adobe, it can get up to "10 times faster" than a program compiled from the equivalent AS3 code, partly because it uses features of the virtual machine that the AS3 compiler does not use. An additional benefit is that it would let us reuse most of the code in the main branch of Box2D without porting it to another language, which would make future updates much easier to bring to Flash.

I'm definitely intrigued. The only thing that bugs me is that it doesn't support Flash Player 9, which is the platform that Box2DAS3 is supposed to support for now.

I'm probably going to experiment with it a little this week. I'll let you know if anything exciting happens.
shaktool wrote:
Well, if we are to believe Adobe, it can get up to "10 times faster" than a program compiled from the equivalent AS3 code, partly because it uses features of the virtual machine that the AS3 compiler does not use.

Ah, ok, I may have read that bit wrong, I thought it just said it would be up to 10 times slower than the equivalent C++. A bump up from AS3 speed would be awesome indeed.

Quote:
I'm definitely intrigued. The only thing that bugs me is that it doesn't support Flash Player 9, which is the platform that Box2DAS3 is supposed to support for now.

Yeah, but it's probably not a huge restriction, or at least it won't be in a little while - at least with Flash you can rely on the fact that most people will upgrade their player versions fairly soon after they are released because the process is so painless (just did it myself now, because the player reminded me to and made it pretty much a one click process). Compare that to Java, where it usually takes several years after a new version is released before you can rely on people actually having it (we're just getting there with Java 1.5, even though 1.6 is now out the door and 1.7 betas are soon to be in the pipe!).

Plus, at least every Flash upgrade tends to actually be an upgrade!
Some quotes from the FAQ:

Quote:
For computation-intensive use cases, such as audio encoding/decoding, data manipulation or cryptographic functions, performance of code ported using the Alchemy tool chain can be ten times faster or more than native ActionScript 3.0 and anywhere from 2-10 times slower than native C/C++ code.
Quote:
The Alchemy team is working closely with the Flash Player and compiler teams, and Adobe expects that many if not all of the performance improvements from Alchemy will find their way into the shipping compilers and players.

So it sounds like an Alchemy version of Box2D would be faster, but maybe only until Adobe releases a better AS3 compiler. That means that the only certain long term benefit to Box2DAS3 would be sharing most of its codebase with the main branch of Box2D, instead of needing to port every update. Which is still really nice, but on the other hand, the AS3 API for Box2D might need to change a lot to accommodate the Alchemy library, and that wouldn't be cool.
In the FAQ, it explicitly mentions physics simulation as a possible use. I bet we are the only project in existence that already has Flash API and user base, with corresponding C++ code already written, so I'm definitely keen to hear how it goes, shaktool.

It also makes it clear that while LLVM is a better compiler than the current Adobe offerings, it makes use of ByteArray AVM2 instructions that the Adobe compiler doesn't generate. And likely never will, as there is no typing on them. So, don't expect the AS3 compiler to recover quickly from this.

This excites me. It's always been frustrating how much performance has been lost in the translation from C++->AS3->AVM2 bytecode. Like not even being able to copy b2Vec2's without creating a new object.
I already found that there are indeed 12 new undocumented Flash10 AVM2 opcodes that are used by Alchemy. I'm planning to use them in the haXe compiler to enable the same speedup possibilities 😉 This should highly benefit projects such as Physaxe (http://code.google.com/p/physaxe).
How do you find undocumented things like this. I though AVM2 bytecode wasn't even open in the first place, let along trying random new bytecodes.
AVM2 bytecode is documented, and before it was I worked on reverse engineer it for haXe compiler.
See my blog post about Alchemy : http://ncannasse.fr/blog/adobe_alchemy
I think we should be a bit careful about forking flash physics engines too much. There are some great people that can really help physics in flash improve, and it'd be nice to have them working on the same engine as much as possible. Box2D for AS3 is really easy to get into, and that is reflected in the amount of applications that use it. I'd rather have one cumbersome but well supported Box2D, than a number of forks that end up dead somewhere along the road. Glaze is a great engine performance-wise, but it has been a while since the last update, (I can't even contact the creator), and APE had a nice API, but has been dead for even longer. Even though Box2DAS3 might be a bit of a compromise, it is so awesome because of it's all-roundness.

Original thread: https://box2d.org/forum/viewtopic.php?t=1794