efficiency testing local vs global variables

Share and discuss your flows and ideas with other users.

Moderator: Martin

Post Reply
User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

efficiency testing local vs global variables

Post by Bushmills » 23 May 2016 00:15

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: efficiency testing local vs global variables

Post by Martin » 23 May 2016 18:45

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.

Post Reply