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:
4DBug committed 2026-11-02 21:12:36 -06:00
1 parent dde6be117c
commit a87ad99410
12 files changed
+802 -710

No files matched your search

+9 -4
View File
@@ -71,8 +71,12 @@ do
for i = 0, 63 do
buffer.writeu16(q, i * 2, 1 + rand(40))
end
local div = table.create(64, 0) -- fdctQuantize's divisors: q * 8
for i = 1, 64 do
div[i] = buffer.readu16(q, (i - 1) * 2) * 8
end
local coef = buffer.create(128)
Dct.fdctQuantize(src, 8, 0, 0, 8, 8, q, coef, 0)
Dct.fdctQuantize(src, 8, 0, 0, 8, 8, div, coef, 0)
for v = 0, 7 do
for u = 0, 7 do
local s = 0
@@ -88,6 +92,7 @@ do
end
end
t:check(worst <= 0.75, "fdct + quantise within rounding of the float reference: " .. worst)
local div1 = table.create(64, 8)
local rt = 0
for _ = 1, 100 do
local src = buffer.create(64)
@@ -95,7 +100,7 @@ do
buffer.writeu8(src, i, rand(256))
end
local coef = buffer.create(128)
Dct.fdctQuantize(src, 8, 0, 0, 8, 8, ones, coef, 0)
Dct.fdctQuantize(src, 8, 0, 0, 8, 8, div1, coef, 0)
local plane = buffer.create(128)
Dct.idctBlock(coef, 0, ones, plane, 0, 8, 2, 128, 255)
for i = 0, 63 do
@@ -112,8 +117,8 @@ do
end
end
local a, b = buffer.create(128), buffer.create(128)
Dct.fdctQuantize(small, 3, 0, 0, 3, 2, ones, a, 0)
Dct.fdctQuantize(ext, 8, 0, 0, 8, 8, ones, b, 0)
Dct.fdctQuantize(small, 3, 0, 0, 3, 2, div1, a, 0)
Dct.fdctQuantize(ext, 8, 0, 0, 8, 8, div1, b, 0)
t:check(buffer.tostring(a) == buffer.tostring(b), "edge replication")
end