Page 1 of 1

efficiency testing local vs global variables

Posted: 23 May 2016 00:15
by Bushmills
I wondered whether efficiency considerations regarding use of local vs. global variables could be neglected because of only minor differences of performance (= power drain), and put together this little flow to measure.
It's up to yourself to draw your own conclusions - here is the flow:
http://automagic4android.com/flow.php?i ... 6f55a45797

Surprised by the impact, I modified the flow towards assigning to variables only:
http://automagic4android.com/flow.php?i ... e3fd5151db

Now the same, but focusing on reading:
http://automagic4android.com/flow.php?i ... f8f3f2be28

It appeared that reading, then writing back to global variables is costly, but then I modified the second flow, to assign a non-literal and varying number:
http://automagic4android.com/flow.php?i ... b905341f29

My conclusions are not final, as it appears that more testing may be needed. My current impression is: writing to globals is expensive, reading is cheap (caching?), so in an attempt to improve performance, action script determines whether an assignment to a global actually modifies its value before writing it back.

Re: efficiency testing local vs global variables

Posted: 23 May 2016 18:45
by Martin
Assignment to global variables is slower since there could be triggers Global Variable that need to be informed or custom widgets that display the global variable. Additionally, global variables are persisted to storage. Performance is best by just using local variables when the values don't need to be stored across flow executions or restarts.