Tested on a Roku 3
Count=10000000 ' 10 million
X = 1000: SW = Epoch(): for Y = 1 to Count: Z = X: end for: ? Epoch()-SW
X = { X:1000 }: SW = Epoch(): for Y = 1 to Count: Z = X.X: end for: ? Epoch()-SW
m.X = 1000: SW = Epoch(): for Y = 1 to Count: Z = m.X: end for: ? Epoch()-SW
m.Global.AddFields({X: 1000}): SW = Epoch(): for Y = 1 to Count: Z = m.Global.X: end for: ? Epoch()-SW
... code to fill reg variable (as a string)... SW = Epoch(): for Y = 1 to 10,000,000: Z = RegistrySection.Read("X"): end for: ? Epoch()-SW
2.187 seconds, 5.562 seconds, 5.548 seconds, 40.905 seconds, and 45.485 seconds respectively
An AA dereference is less than half the performance of a direct variable, that's not a surprise as it is basically 2 variable references, but global access is almost as the same as registry read performance, 7 times slower than X.X, and 18 times slower than a direct variable, so global variables are rather expensive compared to other AA variables, I am assuming there is serialization/deserialization involved.
None of this matters except in high count tight loops. Out of habit I hoist global variables (and obviously registry variables) that are accessed more than once in a code block, so will definitely continue doing that in loops.
Epoch code is
Interesting comparison! Yes, I also hoist global variables for fast use in functions.
This is interesting, thanks. Also, if anyone ever needs to force a Roku reboot just run this in the render thread. 🙂
Yes I run these on the render thread on a Roku 3, but mega loops like this can absolutely reboot the device..
A few more...
I guess I'll try to remember that "append" is a tricky vocab word, whereas "add or replace" are straightforward simple concepts, thus run faster!
We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. You will not be able to log in or post new comments or kudos during this time. Read more here.
Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 12 and you may notice reduced functionality.
In the meantime, for additional assistance, visit our Support Site.
Thanks for your patience — we’re excited to share what’s next!