DumbLuaParser icon indicating copy to clipboard operation
DumbLuaParser copied to clipboard

Suggestion for optimize function

Open SolusJiang opened this issue 3 years ago • 1 comments

replaces calls to global functions with calls to local functions and generates a single line of local variable assignments at the top

so something like :

local function doSomething(s)
      s = string.rep(s, 100)
      print(s)
end

turns into

local string_rep, pring = string.rep, print
local function doSomething(s)
      s = string_rep(s, 100)
      print(s)
end

SolusJiang avatar Dec 01 '22 13:12 SolusJiang

Since this would change the functionality of the code (e.g. prevent dynamic monkey-patching) it's not really fit for the general optimization function, but since this is pretty common to do in Lua I might add an example or code snippet or something that attempts to do this. There are many things to consider though, like functions inside functions. It's also pretty common to put global values used in loops into local variables right before the loop in performance-critical code.

ReFreezed avatar Jan 23 '23 18:01 ReFreezed