- compat math.clamp is vararg: LuaJIT never starts a root trace at a vararg function but still inlines it. The plain shim, called from interpreted code, collected aborted root traces until it was blacklisted, after which every trace through it aborted: in one process, png (or anything earlier) left jpeg / webp / tiff / ImageOps 2-10x slower. - Dct.fdctQuantize: branch-free quantiser and a divisor table (q * 8) from Jpeg.Encode; the sign branch among the column pass's live values made LuaJIT retry side traces it could not compile (register coalescing) forever. Also faster in luau -O2 (~5%) and native (~10%). Outputs unchanged. - tools/bench_mixed.luau + bash tools/bench.sh mixed: core, audio, video, image in one LuaJIT process against the per-codec benches, marking lines more than 1.3x slower mixed.
86 lines
2.9 KiB
Luau
86 lines
2.9 KiB
Luau
-- Mixed-workload check (bash tools/bench.sh mixed), LuaJIT only: bench_core, bench_audio, bench_video and bench_image
|
|
-- in one process, as an app that decodes many formats runs them, the video and image lines against each bench run
|
|
-- alone (the files of its arguments, written by bench.sh). LuaJIT's traces, blacklists and penalties are per process:
|
|
-- a shared helper blacklisted by one codec, or a side trace that never compiles, slows every later caller, which the
|
|
-- per-codec benches never show. Lines more than 1.3x slower mixed than alone are marked.
|
|
local jit = (_G :: any).jit
|
|
if jit == nil then
|
|
print("bench_mixed: LuaJIT only (bash tools/bench.sh mixed)")
|
|
return
|
|
end
|
|
local G = _G :: any
|
|
local loadfile, io = G.loadfile, G.io
|
|
local imageAlone, videoAlone = ...
|
|
|
|
-- "luajit <label> <ms> ms ...": label -> ms, the first time each label is printed
|
|
local function parse(lines: { string }): ({ [string]: number }, { string })
|
|
local ms, order = {}, {}
|
|
for _, l in lines do
|
|
local label, v = string.match(l, "^luajit%s+(.-)%s+([%d%.]+) ms")
|
|
if label and ms[label] == nil then
|
|
ms[label] = tonumber(v) :: number
|
|
table.insert(order, label)
|
|
end
|
|
end
|
|
return ms, order
|
|
end
|
|
|
|
local function readLines(path: string): { string }
|
|
local f = assert(io.open(path, "r"), "bench_mixed: cannot read " .. path)
|
|
local lines = {}
|
|
for l in f:lines() do
|
|
table.insert(lines, l)
|
|
end
|
|
f:close()
|
|
return lines
|
|
end
|
|
|
|
-- runs build/_modules/luajit/tools/<name>.lua in this process and returns what it printed
|
|
local print0 = G.print
|
|
local function run(name: string): { string }
|
|
local lines = {}
|
|
G.print = function(...)
|
|
local parts = table.pack(...)
|
|
for i = 1, parts.n do
|
|
parts[i] = tostring(parts[i])
|
|
end
|
|
table.insert(lines, table.concat(parts :: any, "\t"))
|
|
end
|
|
local chunk = assert(loadfile("build/_modules/luajit/tools/" .. name .. ".lua"))
|
|
local ok, err = pcall(chunk)
|
|
G.print = print0
|
|
assert(ok, err)
|
|
return lines
|
|
end
|
|
|
|
jit.opt.start("maxtrace=8000", "maxmcode=65536")
|
|
print0("bench_mixed: core, audio, video, image in one process")
|
|
run("bench_core")
|
|
run("bench_audio")
|
|
local video = run("bench_video")
|
|
local image = run("bench_image")
|
|
|
|
local marked, total = 0, 0
|
|
local function compare(title: string, alonePath: string?, mixedLines: { string })
|
|
if not alonePath then
|
|
return
|
|
end
|
|
local alone = parse(readLines(alonePath))
|
|
local mixed, order = parse(mixedLines)
|
|
print0(string.format("%-8s %-40s %10s %10s %7s", title, "", "alone ms", "mixed ms", "ratio"))
|
|
for _, label in order do
|
|
local a, m = alone[label], mixed[label]
|
|
if a and a > 0 then
|
|
local r = m / a
|
|
total += 1
|
|
if r > 1.3 then
|
|
marked += 1
|
|
end
|
|
print0(string.format("%-8s %-40s %10.2f %10.2f %6.2fx%s", "luajit", label, a, m, r, if r > 1.3 then " <<" else ""))
|
|
end
|
|
end
|
|
end
|
|
compare("image", imageAlone, image)
|
|
compare("video", videoAlone, video)
|
|
print0(string.format("bench_mixed: %d of %d lines more than 1.3x slower mixed than alone", marked, total))
|