Here’s a question I haven’t found an answer for in either the manual or the forums: what are the best practice guidelines on when to choose between expressions, scripting, or the simpler binding transformations like mapping and formatting? Specifically I’m considering this with regards to performance and memory usage.
I expect that the biggest gain is to ensure that the binding is not being re-evaluated more often than necessary, but ignoring that for a moment, is there a substantial difference between the transform types?
I understand that there are things that can’t be done in the simpler methods and will require expressions or scripting, and there are similarly things that can’t be done in expressions and will require scripting.
But if I’m comfortable with it, is there any drawback to using scripting transforms for everything?
Is it more efficient to chain a bunch of simple transforms together or to use one more complicated expression or scripting transform?
Seat of the pants answer with no performance testing to back it up:
native transforms (ie, mapping) will be faster than
expression transforms will be faster than
“Native” transforms are executing as direct Java code in and out.
Expressions have to be parsed and calculated in steps, so there’s more lookups and variable timing involved.
Scripts will almost certainly be the slowest - we have to either grab or create a Python interpreter, compile the function you provide (we do cache these, but it still has to happen) and then finally execute that using the interpreter and handle the result value.
That said - unless you have literally thousands of transforms on a page, you’re much more likely to notice I/O bottlenecks (tag reads, database queries, HTTP traffic) than transform related slowdown problems.
If you, and anyone who has to maintain the project after you, are more comfortable using scripts, then by all means do so. Avoiding using the tool you are best with would definitely fall into premature optimization, in my opinion.
If this is the case and its preferred to use native transforms or expressions over scripting, is there any way to use them when using an Expression Structure binding? How would I reference these values? I can’t seem to find a way to do it in an expression transform.
Update: so toDataSet() works to make it addressable. I don’t know if adding an expression transform just for that or mixing that in where needed is still more efficient than a script though. I am interested in the most efficient method though because we use a lot of embedded views that contain these bindings on screens.