perf (LuaJIT): stop cross-codec trace pollution in long mixed processes; bench.sh mixed
- 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.
This commit is contained in:
1 parent
dde6be117c
commit
a87ad99410
12 files changed
+802
-710
No files matched your search
+6
-1
@@ -456,8 +456,13 @@ end
|
||||
do
|
||||
-- math.min / math.max are branch-free in a trace; an if / elseif clamp spawned side traces and ran ~3.5x slower.
|
||||
-- NaN stays NaN, as in Luau (maxsd would return lo).
|
||||
-- Vararg (`...` unused): LuaJIT never starts a root trace at a vararg function but still inlines it into its
|
||||
-- callers' traces. The plain clamp, called from interpreted code, started root traces that aborted on the return
|
||||
-- into the caller's loop; enough aborts blacklist it, every trace that reaches a blacklisted function aborts too, and
|
||||
-- in a long mixed process one codec left every clamp user interpreted (jpeg, webp, tiff 2-10x slower). Not done for
|
||||
-- the others: a vararg math.sign made Monkey's Audio's sign-heavy filters ~40% slower.
|
||||
local mmin, mmax = math.min, math.max
|
||||
math.clamp = math.clamp or function(x, lo, hi)
|
||||
math.clamp = math.clamp or function(x, lo, hi, ...)
|
||||
if lo > hi then error("max must be greater than or equal to min", 2) end
|
||||
if x ~= x then return x end
|
||||
return mmin(mmax(x, lo), hi)
|
||||
|
||||
Reference in new issue
Block a user