I use a lot of expressions - to a point where I sometimes get stack overrun errors in renders, and other glitches.
I am wondering if anyone has advice for optimizing expressions and reducing the amount of redundant calculations.
At the moment, the only way I can think of to make a 'comp-level variable', is to create a text layer, calculate something in the 'Source Text' property, and have other expressions refer to that. For numerical values, I might use a Slider or Point control for the same purpose, depending on the value type. Does anyone know if this actually helps to optimize expression evaluation?
Thanks,
Bryan
Was just thinking of a better way to store variables (im hoping that this layer containing the variables is only calculated once every frame)
layer "JAVASCRIPT" sourceText property:
var obj = {
myvar:2,
myothervar:'test',
}
obj.toSource();
Then in an expression in that comp that needs this data:
var obj=eval(thisComp.layer("JAVASCRIPT").text.sourceText.toString());
obj.myvar;
I just hope this is actually helping -- I worry that "eval" may be a heavy operation?
I don't have any test data to back this up, but my experience has been that while there are certain advantages to using controls and text layers to "publish" comp-level variables, efficiency is not one of them. For example, putting the source for a commonly used function in a text layer and using eval() may make for a smaller amount of total code, but it seems to generate a significant performance hit. Again, I haven't done any formal testing--but that's how it seems to me.
Dan
Cool, I'd be interested to know if anyone shares your opinion. If using eval() is the performance killer, I can work around that, by just storing values in expression controls.
My real purpose here isn't to reduce code, but to store comp-level variables that change over time. So, if 20 layers all need to to do one basic calculation, like
var mytime = thisComp.layer('layername').timeRemap*20;
So theoretically I want that calculation done only once, and then the result is piped to wherever it needs to go. Of course, this is simple arithmetic, but I'm storing some variables that may be a bit more costly, for example:
var suffix = /\ (.*)$/i.exec(thisComp.name)[1];
North America
Europe, Middle East and Africa
Asia Pacific