You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by "Michael A. Labriola" <la...@digitalprimates.net> on 2012/02/25 19:42:25 UTC
Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
>The current implementation is that all tags are encoded into an array that gets interpreted during a method call in the lifecycle of the container so it can be intercepted or the array can be modified up front. There are >plans for an API for manipulating the array. It turned out to be much faster to read the array than a data structure.
>But it is just a stake in the ground and can certainly be changed.
Alex,
Is it possible for you to discuss this more here without violating NDAs, etc. with Adobe. To be very clear, I am currently working on the research before implementing a series of compiler changes geared toward run-time performance gains for the framework. I also plan on implementing several features that I have wanted for a while. To that end, I will soon be addressing the way the code gen occurs from MXML as this is a pain point for me. I am hoping to get some of the thoughts you have already on this.
If that's not practical, when I start modifying code, I can just ask for your comments. Right now I am planning on putting this in github as I am modifying the existing compiler bits which are not yet relicensed, approved and in SVN here... so, I think it is ill-advised to commit that here. As soon as those bits are here, I will merge and leave the primary storage in my whiteboard but I don't want to wait to move on this.
Mike
RE: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by "Michael A. Labriola" <la...@digitalprimates.net>.
>I've explained how that could be avoided in a more generic way in the end of the paragraph - why cannot that be a solution? It's ultimately the same mechanism, as you would add event handlers, actually. If you >think about old MXMLC code, you could even use the part that generated event handlers to do that. The benefit would be that:
I am not saying it can't be. Was offering explanation of why they do it.
Ultimately its so that with both databinding and other mechanisms you can set properties on that view independent of its full creation. It just removes that responsibility from the developer.
> The generated "descriptor" on the other hand, is not reusable, it's just some amorphous chunk of data. Of course, it never was a good idea to extend MXML components, but this is not a requirement, given normal >code generation, this limitation can be lifted.
I am not sure I agree with you on the descriptor being a 100% bad idea. I like the fact that MXML acted more as configuration than code. It allowed me to hook its creation and do what I needed to. I really don't want MXML translating directly into object instantiations on my behalf.
Mike
Re: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by Left Right <ol...@gmail.com>.
Ah, and, while at it. There is the IMXMLObject interface and the
initialize(document, id) function in it. The use of this interface and it's
only function is both obscure and illegitimate :) It's most of the time is
used to provide child components with the reference to the parent
component. This allows for creation of dependencies in the direction, they
shouldn't be created (children shouldn't be aware of the parent). So, I
would be in favor of totally eliminating this interface + the functionality
it used to provide. However it was often used (it appears in generated
descriptors all the time), usually, you can just remove it.
Re: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by Left Right <ol...@gmail.com>.
I've explained how that could be avoided in a more generic way in the end
of the paragraph - why cannot that be a solution? It's ultimately the same
mechanism, as you would add event handlers, actually. If you think about
old MXMLC code, you could even use the part that generated event handlers
to do that. The benefit would be that:
1. You can later override this behavior by providing your own
implementation of a function that generates child components.
2. Much easier to use, when creating same components w/o MXML.
This is not entirely a foreign concept - all sorts of labelFunction's and
itemRendererFunction's work in a similar way.
Imagine something like this:
// compare to this._dispatcher.addEventListener("eventType",
this.eventHandler); ?
. . .
this._navigator.addTab("tabTitle", this.makeTab);
. . .
protected function makeTab(title:String):Tab
{
var tab:Tab = new Tab(title);
tab.setStyle("whatever", doesnt, matter);
return tab;
}
Not ideal, but no additional objects are created + more experienced
developers would be able to provide makeTab() implementation which can be
smarter (same function for multiple tabs / generate content based on data).
The makeTab() function may be identified through [DefaultProperty]
metadata, for example.
The generated "descriptor" on the other hand, is not reusable, it's just
some amorphous chunk of data. Of course, it never was a good idea to extend
MXML components, but this is not a requirement, given normal code
generation, this limitation can be lifted.
Best.
wvxvw
RE: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by "Michael A. Labriola" <la...@digitalprimates.net>.
>Is there a reason it can't be done in the same way MSVS designer generates the code? I mean, I know that there is method of UIComponent that can create other components from "descriptor", but I could never >think of a use case that justified that method existence in the first place. If this was a way to allow creating tabs in tab navigator or similar (where the components may not be created right away), then I think that the >component that supports such initialization scheme should provide methods to help that, for example, if it is a tab navigator, then it would have a property `tabs`, with array of functions String -> Tab (string would be >the tab title, and, tab is the new or recycled tab component).
>Or am I missing something?
In the original deferred instantiation scheme (for things like tab nav and viewstack) the out container was create, just not its children. Meaning that each top level container associated with the tab navigator already existed, so people could set data on it, etc. However, when you switched to the tab, it created that containers children at that time.
Mike
Re: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by Left Right <ol...@gmail.com>.
Is there a reason it can't be done in the same way MSVS designer generates
the code? I mean, I know that there is method of UIComponent that can
create other components from "descriptor", but I could never think of a use
case that justified that method existence in the first place. If this was a
way to allow creating tabs in tab navigator or similar (where the
components may not be created right away), then I think that the component
that supports such initialization scheme should provide methods to help
that, for example, if it is a tab navigator, then it would have a property
`tabs`, with array of functions String -> Tab (string would be the tab
title, and, tab is the new or recycled tab component).
Or am I missing something?
Best.
wvxvw
Re: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by Martin Heidegger <mh...@leichtgewicht.at>.
I see. That makes testing of an example a little bit harder. That has to
be a huge array for it to be measurable in ms.
yours
Martin.
On 27/02/2012 17:22, Alex Harui wrote:
>
>
> On 2/26/12 6:10 AM, "Martin Heidegger"<mh...@leichtgewicht.at> wrote:
>> I am not sure how you coded that. I tried it and in my tests custom data
>> structures [1] were a lot faster (10x).
>> Did i understand something wrong?
>>
> I didn't run your test case, but your array example is creating objects on
> the fly and stuffing the array, both of which are expensive. In my test,
> the array is just a sequence of values so the abc code just does a ton of
> pushXXX then newArray
>
Re: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by Alex Harui <ah...@adobe.com>.
On 2/26/12 6:10 AM, "Martin Heidegger" <mh...@leichtgewicht.at> wrote:
> I am not sure how you coded that. I tried it and in my tests custom data
> structures [1] were a lot faster (10x).
> Did i understand something wrong?
>
I didn't run your test case, but your array example is creating objects on
the fly and stuffing the array, both of which are expensive. In my test,
the array is just a sequence of values so the abc code just does a ton of
pushXXX then newArray
--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui
Re: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by Martin Heidegger <mh...@leichtgewicht.at>.
On 26/02/2012 17:02, Alex Harui wrote:
> But I was unable to find something that was faster and still looked like a
> data structure. I did the usual optimizations of loops, local variables,
> class definitions instead of just Object, etc. I think one of the issues is
> the cost of setting up the data structure.
Hello Alex,
I am not sure how you coded that. I tried it and in my tests custom data
structures [1] were a lot faster (10x).
Did i understand something wrong?
yours
Martin.
[1] http://wonderfl.net/c/rBbt
Re: Compiler Array Implementation ( was Adobe / Apache / Spoon Flex
Tour )
Posted by Alex Harui <ah...@adobe.com>.
On 2/25/12 10:42 AM, "Michael A. Labriola" <la...@digitalprimates.net>
wrote:
>> The current implementation is that all tags are encoded into an array that
>> gets interpreted during a method call in the lifecycle of the container so it
>> can be intercepted or the array can be modified up front. There are >plans
>> for an API for manipulating the array. It turned out to be much faster to
>> read the array than a data structure.
>
>> But it is just a stake in the ground and can certainly be changed.
>
> Alex,
>
> Is it possible for you to discuss this more here without violating NDAs, etc.
> with Adobe. To be very clear, I am currently working on the research before
> implementing a series of compiler changes geared toward run-time performance
> gains for the framework. I also plan on implementing several features that I
> have wanted for a while. To that end, I will soon be addressing the way the
> code gen occurs from MXML as this is a pain point for me. I am hoping to get
> some of the thoughts you have already on this.
I will check with my legal advisors on whether I can just copy a
spec/proposal I had written up, but basically, the data I have is that the
method currently generated for a tag turns out to be much faster than I
would have guessed. I expected the cost of verify-and-jit for each of the
methods which only get used once would be easy to recover. It turned out
that the cost of working with a data structure is even more expensive even
though you should be gaining advantages of re-using the verify-and-jit.
For example, if you have N methods that look something like this:
function method1()
{
var foo:Button = new Button();
foo.someProperty = someValue;
foo.setStyle("someStyleProperty", someStyleValue);
addChild(foo);
}
function method2()
{
var foo:Label = new Label();
foo.someOtherProperty = someOtherValue;
foo.setStyle("someOtherStyleProperty", someOtherStyleValue);
addChild(foo);
}
You might want to run them through a data-driven loop:
var childData:Array = [
{ clazz: Button,
properties: [ "someProperty" ];
propertyValues: [ someValue ];
styles: [ "someStyleProperty" ];
styleValues: [ someStyleValue ];
},
{ clazz: Label,
properties: [ "someOtherProperty" ];
propertyValues: [ someOtherValue ];
styles: [ "someOtherStyleProperty" ];
styleValues: [ someOtherStyleValue ];
},
];
for (var index:int = 0; index < childData.length; index++)
{
var childInfo:Object = childData[index];
var foo:UIComponent = new childInfo.clazz();
if (childInfo.properties)
for (var j:int = 0; j < childInfo.properties.length; j++)
foo[childInfo.properties[j]] = childInfo.propertyValues[j];
if (childInfo.styles)
for (var j:int = 0; j < childInfo.styles.length; j++)
foo.setStyle(childInfo.styles[j], childInfo.styleValues[j]);
}
But I was unable to find something that was faster and still looked like a
data structure. I did the usual optimizations of loops, local variables,
class definitions instead of just Object, etc. I think one of the issues is
the cost of setting up the data structure.
What is as fast as the methods is a single array of encoded data with a loop
that decodes it. So, you might pack everything in an array like this:
[ Button, "someProperty", someValue, null, "someStyleProperty",
someStyleValue, null, Label, "someOtherProperty", someOtherValue, null,
"someOtherStyleProperty", someOtherStyleValue"];
You can play around with using null as a delimiter between properties and
styles or putting in the number of properties and styles or whatever, but I
think this is fast because the array setup time is much faster than data
structure setup time, and then you get to leverage the verify-and-jit.
--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui