Skip to content

Commit

Permalink
feat(standard): automatically setup performance testing if enabled (#…
Browse files Browse the repository at this point in the history
…4541)

* feat(standard): automatically setup performance testing if enabled

* these calls do nothing anymore
  • Loading branch information
Rathoz authored Aug 15, 2024
1 parent 51e31ef commit 219639b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
1 change: 0 additions & 1 deletion components/match2/commons/match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ end

if FeatureFlag.get('perf') then
Match.perfConfig = Table.getByPathOrNil(MatchGroupConfig, {'subobjectPerf'})
require('Module:Performance/Util').setupEntryPoints(Match, {'toEncodedJson'})
end

Lua.autoInvokeEntryPoints(Match, 'Module:Match', {'toEncodedJson'})
Expand Down
1 change: 0 additions & 1 deletion components/match2/commons/match_group.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ end

if FeatureFlag.get('perf') then
MatchGroup.perfConfig = Table.getByPathOrNil(MatchGroupConfig, {'perf'})
require('Module:Performance/Util').setupEntryPoints(MatchGroup)
end

Lua.autoInvokeEntryPoints(MatchGroup, 'Module:MatchGroup')
Expand Down
1 change: 0 additions & 1 deletion components/match2/commons/match_subobjects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ end
if FeatureFlag.get('perf') then
local Match = Lua.import('Module:Match')
MatchSubobjects.perfConfig = Match.perfConfig
require('Module:Performance/Util').setupEntryPoints(MatchSubobjects, ENTRY_POINT_NAMES)
end

Lua.autoInvokeEntryPoints(MatchSubobjects, 'Module:Match/Subobjects', ENTRY_POINT_NAMES)
Expand Down
30 changes: 26 additions & 4 deletions standard/lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local FeatureFlag = require('Module:FeatureFlag')
local Logic = require('Module:Logic')
local StringUtils = require('Module:StringUtils')

Expand Down Expand Up @@ -71,7 +72,7 @@ function Lua.import(name, options)
end

local devName = name .. '/dev'
local devEnabled = require('Module:FeatureFlag').get('dev')
local devEnabled = FeatureFlag.get('dev')
if devEnabled and require('Module:Namespace').isMain() then
mw.ext.TeamLiquidIntegration.add_category('Pages using dev modules')
end
Expand Down Expand Up @@ -137,9 +138,12 @@ function Lua.invoke(frame)

local devActive = devEnabled(frame)
local flags = {dev = devActive}
return require('Module:FeatureFlag').with(flags, function()
return FeatureFlag.with(flags, function()
local module = Lua.import('Module:' .. moduleName)
return Lua.callAndDisplayErrors(module[fnName], frame, devActive)
local context = {baseModuleName = 'Module:' .. moduleName, module = module}
return Lua.withPerfSetup(context, function()
return Lua.callAndDisplayErrors(module[fnName], frame, devActive)
end)
end)
end

Expand Down Expand Up @@ -169,6 +173,24 @@ function Lua.callAndDisplayErrors(fn, frame, hardErrors)
return table.concat(parts)
end


---Automatically sets up performance instrumentation if using Lua.invoke
---@param context {baseModuleName: string, module: unknown}
---@param f fun(): ...
---@return ...
function Lua.withPerfSetup(context, f)
if FeatureFlag.get('perf') then
require('Module:Performance/Util').startFromInvoke(context)
end
local function post(...)
if FeatureFlag.get('perf') then
require('Module:Performance/Util').stopAndSave()
end
return ...
end
return post(f())
end

--[[
Incorporates Lua.invoke functionality into an entry point. The resulting entry
point can be #invoked directly, without needing Lua.invoke.
Expand Down Expand Up @@ -204,7 +226,7 @@ function Lua.wrapAutoInvoke(module, baseModuleName, fnName)
end

local flags = {dev = Logic.readBoolOrNil(dev)}
return require('Module:FeatureFlag').with(flags, function()
return FeatureFlag.with(flags, function()
local variantModule = Lua.import(baseModuleName)
local fn = module == variantModule and moduleFn or variantModule[fnName]
return fn(frame)
Expand Down

0 comments on commit 219639b

Please sign in to comment.