Re: [script] Performance - puzzled

Date : Tue, 16 May 2006 16:31:41 -0400
To : XSI(at)Softimage.COM
From : "Bernard Lebel" <3dbernard(at)gmail.com>
Subject : Re: [script] Performance - puzzled
Amazing.

It now clocks at 0.4 seconds for each parameter. Much better, although
I only have 339 parameters to update.... Anyway, that will do for now.


Thanks Brad Bernard



On 5/16/06, brad <brad(at)cg-soup.com> wrote:
Getting a pointer to any parameter using the syntax:  node.parameters('paramName')   is quite slow when compared to other methods, and that's what is most likely reducing your performance. You can test this by running your script by only  getting pointers to those nodes without setting any values.

Populating collections using the Items property is about 10 times faster:

    coll.Items = "ModelName" + ".*.PropertyName.paramName"

Once you have the collection populated, loop through and update all the values. This script shouldn't take longer than a half second on a full sized production rig ~1000 X3D nodes.

-Brad


> -------Original Message------- > Hello, > > I have this property plugin that I on a model. This property is called > "metamodel". Contains few informations about the model, like the model > ID, a one-word description, the project, etc. > > Now, many objects children of this model have their own version of > this property, called "metaobject". This property has a fewer amount > of parameters than "metamodel", but has those that I have named. > > Now, the "metamodel" property has a bunch of callbacks that when you > change a value, this new value is propagated down to each "metaobject" > property. > > I have been trying to find out the fastest way to propagate down the > new values, and I have come accross a behavior that I can hardly > explain. I have tried 3 different solutions. > > > 1- Traverse children only once, update all parameters at once > > At the end of every "metamodel" callback, there would be a call to the > function that updates the children properties. This function would be > called only once. During the update, the desired parameter values > would be transfers from "metamodel" to "metaobject", explicitely: > > oChildProp.parameters( 'Project' ).value = oModelProp.parameters( > 'Project' ).value > oChildProp.parameters( 'ElementType' ).value = oModelProp.parameters( > 'ElementType' ).value > oChildProp.parameters( 'ElementFullID' ).value = > oModelProp.parameters( 'ElementFullID' ).value > oChildProp.parameters( 'ElementDescription' ).value = > oModelProp.parameters( 'ElementDescription' ).value > oChildProp.parameters( 'ElementRoot' ).value = oModelProp.parameters( > 'ElementRoot' ).value > oChildProp.parameters( 'ElementMain' ).value = oModelProp.parameters( > 'ElementMain' ).value > oChildProp.parameters( 'SubElementName' ).value = > oModelProp.parameters( 'SubElementName' ).value > > This clocks at 11-13 seconds. > > > > 2- Traverse the children several times, update only a handful of > parameters at a time > > This one uses a completely different approach. The "metamodel" > callbacks calls a one or more functions, and these functions may or > may not call additional functions. At the end of each single function > called, the function that updates the "metaobject" properties is > called. But this time, only the parameter names and values to update > are passed: > > # Iterate tuples of parameter name-value pairs > for tPair in tPairs: > > # Extract parameter script name and value > sParameterName = tPair[0] > oParameterValue = tPair[1] > > # Check if script name is among the metaobject property > if not oChildProp.parameters( sParameterName ): > pass > else: > oChildProp.parameters( sParameterName ).value = oParameterValue > > > When I tested it, that function was called twice, and both calls > clocked at 2-3 seconds, for a total of 4-6 seconds. This is about 2-3 > faster than the approach #1. > > > > 3- Traverse children only once, but bind name to parameter values, > update all parameters at once > > This time I have the exact same approach as with #1, except that in > the beginning of the function, I bind a name to the parameter values > that I'm transferring: > > oChildProp.parameters( 'Project' ).value = sProject > oChildProp.parameters( 'ElementType' ).value = sElementType > oChildProp.parameters( 'ElementFullID' ).value = sElementFullID > oChildProp.parameters( 'ElementDescription' ).value = sElementDescription > oChildProp.parameters( 'ElementRoot' ).value = sElementRoot > oChildProp.parameters( 'ElementMain' ).value = sElementMain > oChildProp.parameters( 'SubElementName' ).value = sSubElementName > > This time, it clocks at roughly 6-7 seconds. This is much better, but > I still can't conceive why it takes so much more time than the > approach #2! > > > > > Somehow I was expecting the opposite. I figured that only one call to > traverse the children of the model would make things faster, but it's > not. Anyone has any idea? > > (sorry providing the whole code would make for quite a long post, but > hopefully what I have given here is sufficient....) > > > > Thanks > Bernard > > --- > Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: > unsubscribe xsi > --- Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: unsubscribe xsi


--- Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.