TEST 1: Localize
Code:
local min = math.min
Results:
Non-local: 0.719 (158%)
Localized: 0.453 (100%)Conclusion:
Yes, we should localize all standard lua and Spring API functions.
Source: https://springrts.com/wiki/Lua_Performance
What is the reason for that performance boost?
local min = math.min
Remember that table.name
is just syntax sugar for table["name"]
(they're exactly equivalent). And globals are just keys in the environment table, so math.min
is _ENV["math"]["min"]
. That's two hashtable lookups to get at the actual function value.
Copying the value into a local
puts it in a VM register so there's no lookup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With