Spicefactory Forum Index Spicefactory
Forum Archive
 
 SearchSearch    Log inLog in 

FastInject and multiple contexts

 
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory
View previous topic :: View next topic  
Author Message
maurice.amsellem



Joined: 15 Nov 2010
Posts: 17
Location: France

PostPosted: Tue May 22, 2012 5:10 pm    Post subject: FastInject and multiple contexts Reply with quote

Hi Jens,

My application consists of complex components that are instantiated several times. Because of that, each component manages its own child context, so that injection by type works correctly, and a top-level context for the app itself.

I would like to use FastInject to boost performance of the application.
AFAIK, the very idea of FastInject is to avoid having UIComponents managed by Parsley at all, to avoid the reflection.
However, since FastInject will use the closest child Context on the view hierarchy, I understand that at least the root UI container of each component must have a ContextBuilder tag, which means that it will be managed by Parsley and the reflection on the UI top container will occur (but not on the subviews).

Is my understanding correct ?
Or is there a mean of avoiding also the reflection on that root container?

Thanks for your help.

Maurice Amsellem
_________________
Flex 4 - CG3 + Parsley
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Wed May 23, 2012 7:55 am    Post subject: Reply with quote

A ContextBuilder does not need to reflect on its view root. Or in other words, the view root itself is not automatically part of that Context as a managed object. The view root of a Context is merely the boundary that tells you that child components below that view root are seen as being associated with that Context in case there is a Configure or FastInject to process.

That's also why you sometimes see people post code examples where they have a ContextBuilder and a Configure side by side. If they want the view root to be a managed object in that Context they explicitly have to state so. And only with Configure (or view autowiring) reflection on views occurs.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
maurice.amsellem



Joined: 15 Nov 2010
Posts: 17
Location: France

PostPosted: Wed May 23, 2012 8:28 am    Post subject: Reply with quote

Excellent! Thank you a lot for the quick response and keep up the good job
_________________
Flex 4 - CG3 + Parsley
Back to top
View user's profile Send private message
maurice.amsellem



Joined: 15 Nov 2010
Posts: 17
Location: France

PostPosted: Thu May 24, 2012 6:03 pm    Post subject: FastInject and Popups Reply with quote

I am currently implementing FastInject following your guidelines and I am having trouble with Popups

Section 8.8 of the Parsley 2.4 documentation says:

The following code snippet assumes that it is either part of a wired MXML component or another tpye of object managed by Parsley, so that the injection is actually performed:
Code:

 public var context:Context;
context.viewManager.addViewRoot(win);
    PopUpManager.addPopUp(win, this);


I am using FastInject everywhere, so no MXML component is wired to the context not even the Application , and I can't use wired PM objects either to execute this code, because they are not supposed to know about their UIs.

So should I make an exception, and wire the top level Application to the context, so that the code can execute there ?

Thanks for your advice
_________________
Flex 4 - CG3 + Parsley
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Fri May 25, 2012 9:01 am    Post subject: Reply with quote

The same section in the manual shows a declarative way of creating popups. This might work better in your case.

Programmatically, if you FastInject some PM for example into the view and the view has an Inject for a Parsley Context, then you can also use that Context in the code sample you showed.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
maurice.amsellem



Joined: 15 Nov 2010
Posts: 17
Location: France

PostPosted: Fri May 25, 2012 1:46 pm    Post subject: FastInject performance improvement result Reply with quote

Thanks Jens,

I have completed the move to FastInject (now only PM classes (not deriving from UIComponent) are now managed in the context).
I have profiled the improvement, and wanted to share a few results from the profiler :
Code:
                                       Without FastInject / with FastInject
ClassInfo.getClassDefinitionByName: 
                         #calls :      35800 / 15800
                  cumulative time:      85ms / 57ms.

Not really worth it!
So I guess that since FP 10.1 and describeTypeJSON, loading UIComponent metadata is not an issue anymore (at least for me Very Happy ).

Or maybe I didn't look at the right method.

Regards
_________________
Flex 4 - CG3 + Parsley
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Fri May 25, 2012 3:39 pm    Post subject: Reply with quote

The numbers are misleading as the result often comes from the Spicelib Reflect cache. The FP 10.1 improvements roughly reduced the time needed for reflection to 50%, so for very big apps, working without FastInject still makes them close to being unusable.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
maurice.amsellem



Joined: 15 Nov 2010
Posts: 17
Location: France

PostPosted: Fri May 25, 2012 7:14 pm    Post subject: Reply with quote

You are correct.
I did other higher level measures and it shows that setup of each child context is now twice faster.
Thanks a lot for your support.
_________________
Flex 4 - CG3 + Parsley
Back to top
View user's profile Send private message
maurice.amsellem



Joined: 15 Nov 2010
Posts: 17
Location: France

PostPosted: Fri May 25, 2012 7:54 pm    Post subject: FastInject and SkinnableComponent Reply with quote

One last question, I promise:

During the training I received on Parsley, we were told that we could alternatively use Spark's SkinnableContainer as PMs.
In this case, the view is the skin of the container.
The main advantage of this approach is that you can declare the views in css files (nice de-coupling), and the model is automatically injected in "hostComponent".
The downside is that the model is itself an UIComponent, and takes one more level on the UI hiearchy, and injection is slower.
Also, the PM is rather a mediator because it knows of its skinParts.

I am using this technique for a few of the PMs and thought that FastInject could also work here, using AS syntax.

What do you think ?
_________________
Flex 4 - CG3 + Parsley
Back to top
View user's profile Send private message
Jens Halm
Site Admin


Joined: 21 Sep 2007
Posts: 2631
Location: Cologne, Germany

PostPosted: Tue May 29, 2012 8:43 am    Post subject: Reply with quote

This probably would be something for a new thread as it moves into new ground. It would make it easier for others to find relevant content.

Regarding your question I can keep it short though: I think your trainer really suggested something which smells like a big anti-pattern to me. It kind of abuses a construct that has been introduced for a particular purpose (skinning) to cram something completely different (application logic) into it. I've never seen anyone use this approach.
_________________
Jens Halm
Spicefactory
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Spicefactory Forum Index -> Spicefactory All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group