tags:

views:

457

answers:

3

Does MXML get compiled down to as3 and then converted to flash bytecode? Also, is there a significant performance penalty to compiling mxml vs compiling as3?

+4  A: 

Yes it boils down to AS3, most, possibly all MXML components are just a tag version of an AS3 class.

There is no raw difference in compile times, however, because MXML requires the Flex framework, MXML projects do take longer to compile.

So... in a way, MXML is slower, but not dramatically so.

Jasconius
I see that the compiler can keep the generated as3 sources via a compile flag. So the answer to both is basically "yes". MXML generates as3, and the extra step does add some perf overhead (probably not a huge amount in most cases, though, as the conversion to as3 must be pretty cheap for all but very large classes).
jsight
Not quite, you're close... but MXML doesn't "do" anything. MXML is only a tag representation of an AS3 class. The AS3 isn't "generated". It's already sitting somewhere in the framework. When you do MXML:Label, that's just pointing to a Label.as file somewhere in the Flex framework. The performance overhead comes in because Flex has a ton of dependencies that have to be compiled that a raw AS3 project does not.
Jasconius
I mean, you could argue that mapping tag attributes to AS3 class properties is overhead, but you'd have to have an f'ing huge MXML project to even notice it. The biggest thing that adds to Flash/Flex compile times is media embedding (images, sounds, etc).
Jasconius
jsight
OH, I see what you are getting at. I had a crisis of terminology. Yes, the MXML documents you write *do* get compiled to AS3, I was referring to MXML *controls* which are the tags you actually use within the document. The controls represent AS3 already. The document itself does get compiled, and yes, it is slower.
Jasconius
MXML doesn't actually require the Flex framework: http://www.ryancampbell.com/2009/08/26/using-mxml-without-flex-example-and-source/
joshtynjala
+2  A: 

This is a bit of a correction of Jasconius.

All MXML functions as a form of pre-compiler directive to generate a Class. mxmlc.exe will convert it to a series of temporary .as files before running the final compiler. Actually, you can see how the compiler does this by using the instruction keep-generated-actionscript.

Because this is a two-step process, this will mean that it will always take longer to compile something written with MXML. But, even on slower machines and large projects, that will not cause significant difficulties -- the real problem comes in converting everything into bytecode. But, this is not without benefit.

The major bonus of the MXML syntax is that it is easier to read, it is easier to conceptualize, and it is easier to debug. It also makes it much simpler to separate form and content. Any time you might loose in the compilation process, you will gain back ten-fold while programming.

Christopher W. Allen-Poole
Yeah, we sorted it out in the comments. I got confused between tags and documents. I don't work on Flex but once a year perhaps. O.o
Jasconius
A: 

A simple hello world application in flex will be more than 100k in flex compared to a couple of kbs in a pure AS3 project. This is because flex compiles a lot of dependencies into your swf. So yeah, there is a penalty in terms of bandwidth required.

Compile a simple flex app after adding -keep to additional compiler arguments field in the project|properties|flex compiler and then check the autogenerated folder named generated in your source folder to see the stuff that the compiler generates.

Amarghosh