Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
Minor runtime optimization with deoptimized env
Browse files Browse the repository at this point in the history
  • Loading branch information
regginator committed Jan 31, 2023
1 parent 5f80779 commit 40e5820
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .maui.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@

"MinifyTable": true,
"UseMinifiedLoader": true
},

"Flags": {
"ContextualExecution": false
}
}
6 changes: 4 additions & 2 deletions src/Codegen/LoadModuleCode/LoadModule.lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ do
end
end

local RealEnvironment = getfenv(0)

local ReferenceBindings = {}
local ReferencesToSet = {}

Expand Down Expand Up @@ -80,6 +78,10 @@ do
end
end

local RealEnvironment = getfenv(0)

local script, unpack, table, require, type, pcall, getfenv, setfenv, setmetatable, rawget, coroutine, task = script, unpack, table, require, type, pcall, getfenv, setfenv, setmetatable, rawget, coroutine, task

local function LoadScript(scriptObject)
local StoredModuleValue = StoredModuleValues[scriptObject]
if scriptObject.ClassName == "ModuleScript" and StoredModuleValue then
Expand Down
2 changes: 1 addition & 1 deletion src/Codegen/LoadModuleCode/LoadModule.min.lua.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
do local a,b='${Version}',Flags or{}local c,d,e=(b.ContextualExecution==nil and true)or b.ContextualExecution do if c then local f=game:GetService'RunService'd=f:IsServer()e=f:IsClient()end end local f,g,h,i,j,k,l=getfenv(0),{},{},{},{},{},{}local function m(n)local o,p=pcall(Instance.new,n.ClassName)if not o then return end g[n.Reference]=p if n.Closure then i[p]=n.Closure if p:IsA'BaseScript'then table.insert(k,p)end end if n.Properties then for q,r in next,n.Properties do pcall(function()p[q]=r end)end end if n.RefProperties then for q,r in next,n.RefProperties do table.insert(h,{InstanceObject=p,Property=q,ReferenceId=r})end end if n.Attributes then for q,r in next,n.Attributes do pcall(p.SetAttribute,p,q,r)end end if n.Children then for q,r in next,n.Children do local s=m(r)if s then s.Parent=p end end end return p end local n={}do for o,p in next,ModuleRoot do table.insert(n,m(p))end end local function o(p)local q=j[p]if p.ClassName=='ModuleScript'and q then return unpack(q)end local r=i[p]if not r then return end do local s local t={['maui']=table.freeze{Version=a,GetScript=function()return script end,GetShared=function()return l end},['script']=p,['require']=function(t,...)if t and t.ClassName=='ModuleScript'and i[t]then return o(t)end return require(t,...)end,['getfenv']=function(t,...)if type(t)=='number'and t>=0 then if t==0 then return s else t=t+1 local u,v=pcall(getfenv,t)if u and v==f then return s end end end return getfenv(t,...)end,['setfenv']=function(t,u,...)if type(t)=='number'and t>=0 then if t==0 then return setfenv(s,u)else t=t+1 local v,w=pcall(getfenv,t)if v and w==f then return setfenv(s,u)end end end return setfenv(t,u,...)end}s=setmetatable({},{__index=function(u,v)local w=rawget(s,v)if w~=nil then return w end local x=t[v]if x~=nil then return x end return f[v]end})setfenv(r,s)end local s=coroutine.wrap(r)if p:IsA'BaseScript'then local t=(not c or not p.Disabled)and task.defer(s)if c then local u u=p:GetPropertyChangedSignal'Disabled':Connect(function(v)u:Disconnect()if v==false then o(p)else pcall(task.cancel,t)end end)end return else local t={s()}j[p]=t return unpack(t)end end for p,q in next,h do pcall(function()q.InstanceObject[q.Property]=g[q.ReferenceId]end)end for r,s in next,k do if not c or((d and s.ClassName=='Script')or(e and s.ClassName=='LocalScript'))then o(s)end end if b.ReturnMainModule==nil or b.ReturnMainModule then local t do for u,v in next,n do if v.ClassName=='ModuleScript'and v.Name=='MainModule'then t=v break end end end if t then return o(t)end end end
do local a,b='${Version}',Flags or{}local c,d,e=(b.ContextualExecution==nil and true)or b.ContextualExecution do if c then local f=game:GetService'RunService'd=f:IsServer()e=f:IsClient()end end local f,g,h,i,j,k={},{},{},{},{},{}local function l(m)local n,o=pcall(Instance.new,m.ClassName)if not n then return end f[m.Reference]=o if m.Closure then h[o]=m.Closure if o:IsA'BaseScript'then table.insert(j,o)end end if m.Properties then for p,q in next,m.Properties do pcall(function()o[p]=q end)end end if m.RefProperties then for p,q in next,m.RefProperties do table.insert(g,{InstanceObject=o,Property=p,ReferenceId=q})end end if m.Attributes then for p,q in next,m.Attributes do pcall(o.SetAttribute,o,p,q)end end if m.Children then for p,q in next,m.Children do local r=l(q)if r then r.Parent=o end end end return o end local m={}do for n,o in next,ModuleRoot do table.insert(m,l(o))end end local n,o,p,q,r,s,t,u,v,w,x,y,z=getfenv(0),script,unpack,table,require,type,pcall,getfenv,setfenv,setmetatable,rawget,coroutine,task local function A(B)local C=i[B]if B.ClassName=='ModuleScript'and C then return p(C)end local D=h[B]if not D then return end do local E local F={['maui']=q.freeze{Version=a,GetScript=function()return o end,GetShared=function()return k end},['script']=B,['require']=function(F,...)if F and F.ClassName=='ModuleScript'and h[F]then return A(F)end return r(F,...)end,['getfenv']=function(F,...)if s(F)=='number'and F>=0 then if F==0 then return E else F=F+1 local G,H=t(u,F)if G and H==n then return E end end end return u(F,...)end,['setfenv']=function(F,G,...)if s(F)=='number'and F>=0 then if F==0 then return v(E,G)else F=F+1 local H,I=t(u,F)if H and I==n then return v(E,G)end end end return v(F,G,...)end}E=w({},{__index=function(G,H)local I=x(E,H)if I~=nil then return I end local J=F[H]if J~=nil then return J end return n[H]end})v(D,E)end local E=y.wrap(D)if B:IsA'BaseScript'then local F=(not c or not B.Disabled)and z.defer(E)if c then local G G=B:GetPropertyChangedSignal'Disabled':Connect(function(H)G:Disconnect()if H==false then A(B)else t(z.cancel,F)end end)end return else local F={E()}i[B]=F return p(F)end end for B,C in next,g do t(function()C.InstanceObject[C.Property]=f[C.ReferenceId]end)end for D,E in next,j do if not c or((d and E.ClassName=='Script')or(e and E.ClassName=='LocalScript'))then A(E)end end if b.ReturnMainModule==nil or b.ReturnMainModule then local F do for G,H in next,m do if H.ClassName=='ModuleScript'and H.Name=='MainModule'then F=H break end end end if F then return A(F)end end end

0 comments on commit 40e5820

Please sign in to comment.