Differences between [Inject] and [FastInject] tags

In order to illustrate the difference between [Inject] and [FastInject] we first need to know the difference between describeType and describeTypeJSON functions.

describeType:  The describeType() method returns an xml dump that contains all the details you’d ever need to know about any object that is passed in as a parameter. This method implements the programming concept of reflection API for the ActionScript language.

Ex: trace(flash.utils.describeType(flash.display.MovieClip));

Note: describeType() only shows public properties and methods, and will not show properties and methods that are private, package internal or in custom namespaces. If you need only to traverse an object’s inheritance hierarchy and do not need the other information provided by describeType(), use the getQualifiedClassName() and getQualifiedSuperclassName() functions instead.

More on this topic at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#describeType()

describeTypeJSON:  With this  method it’s possible to retrieve reflection data as an object and to filter certain types of information using the constants.

FLASH10_FLAGS = 1535

package avmplus
    public function getInterfaces(object:*):Array
        return describeTypeJSON(object, INCLUDE_TRAITS | INCLUDE_INTERFACES).traits.interfaces;

Note:  The describeTypeJSON is defined in the avmplus.* package and supported for Flash Player 10.1

More on this topic at http://www.tillschneidereit.de/2009/11/22/improved-reflection-support-in-flash-player-10-1/

[Inject] v/s [FastInject]:

Parsley has the ability of reflection API which reflects on all managed objects and reflection of components which is very expensive operation due to numerous number of properties,methods and events. Which means that Parsley   2.1 and below uses describeType() method on all of its manages objects. [Inject] tag uses the describeType() method to introspect its managed objects.

Introduced in Parsley 2.2, the [FastInject] tag is the key to the performance optimization. [FastInject] uses the describeTypeJSON() method which is faster than describeType(). Note that the impact of reflecting huge UIComponents is still high. Parsley maintains an internal reflection cache, so that each class is only processed once, but if you are using a high number of different component classes this may not help much.In a smaller application this effect is negligible but its a concern for larger applications.

<parsley:FastInject property="model" type="{MyPanelPM}" /> 
<parsley:FastInject injectionComplete="init();"> 
 <parsley:Inject property="model" type="{MyPanelPM}"/> 
 <parsley:Inject property="status" type="{MyApplicationStatus}"/> 
Action Script:
function MyView () { 
 FastInject .view(this) 

private function injectionComplete () : void { /* ... */ }

Corrections:  describeType() and describeTypeJSON() are not included in Parsley framework, they are part of avmplus package of the Flash Player. describeTypeJSON is provided in Flash Player 10.1 and above.

reflection in fp 10.1

If the user runs the Flex Application built with Parsley framework against Flash Player’s versions 10.1 and above, Parsley intelligently uses the faster describeTypeJSON() and if the application is run against Flash Player versions below 10.1, Parsley uses  the slower describeType()

In reality, FastInject neither uses describeType() nor describeTypeJSON(). FastInject is used for injecting a managed object from the nearest Context in the view hierarchy into a view without reflecting on the view. This way the FastInject  retrieves a particular object from the IoC Container without actually getting wired to it to avoid the cost of reflection and hence its fast.



2 thoughts on “Differences between [Inject] and [FastInject] tags

  1. Unfortunately the key facts of this post are incorrect. In reality this is how it works:

    1) Since Parsley 2.4 *all* reflection happens based on the faster describeTypeJSON if it is available and only falls back to describeType when not. So if describeTypeJSON is available, the slower describeType won’t be used for any of Parsley’s features (as there is no need to).

    2) FastInject is very fast as it avoids reflection altogether. It uses neither describeType nor describeTypeJSON. Since even the latter is still quite slow for reflecting on UIComponents it can be used inside views as a significant performance improvement. In the example above you can see that no reflection at all is involved, as you have to specify the target property name and type. With reflection the framework would know the type.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s