merge master into ws/3d3 (ws/roblox, ws/voxel, ...)

This commit is contained in:
4DBug committed 2026-10-31 15:20:28 -05:00
commit 98b04367c6
68 files changed
+13623 -31

No files matched your search

+126 -1
View File
@@ -1,7 +1,7 @@
-- Throughput (bash tools/bench.sh): codec MB/s under both runtimes. MB/s are of decompressed output, best of n runs.
-- Fixtures: tools/fixtures/deflate.py (a 6 MB corpus), tools/fixtures/png.py (1024 x 768 images), tools/fixtures/mp3.py,
-- tools/fixtures/opus.py (3 s stereo files; MB/s of f32 output, 48 kHz stereo f32 is 0.384 MB/s of real time),
-- tools/fixtures/flac.py; wav encodes / decodes a generated tone; zstd / brotli / bzip2 / lzma (*_bench corpora), fonts
-- tools/fixtures/flac.py; wav encodes / decodes a generated tone; zstd / brotli / bzip2 / lzma / lz4 (*_bench corpora), fonts
-- (glyphs per second), json / xml / yaml, jpeg / gif / tiff / qoi / tga / pnm / hdr and ImageOps.
local Deflate = require("@formats/codecs/compress/Deflate")
local Crc32 = require("@formats/core/Crc32")
@@ -236,6 +236,53 @@ do
Zstd.decompress(z19, nil, nil, { verify = false })
end)
end
do
local Lz4 = require("@formats/codecs/compress/Lz4")
local LB = require("@tests/gen/lz4_bench")
local lz = buffer.fromstring(LB.data)
local raw = assert(Lz4.decompress(lz, nil, nil, LB.size))
assert(Crc32.of(raw) == LB.crc, "lz4 bench corpus mismatch")
bench("lz4 block decompress (hc9)", 5, LB.size, function()
Lz4.decompress(lz, nil, nil, LB.size)
end)
bench("lz4 block compress", 3, LB.size, function()
Lz4.compress(raw)
end)
end
-- ws-roblox: a model of 20000 parts (built here) through model/rbxm and model/rbxmx, and a .mesh decode
do
local Rbx = require("@formats/codecs/model/Rbx")
local Rbxm = require("@formats/model/rbxm")
local Rbxmx = require("@formats/model/rbxmx")
local RobloxMesh = require("@formats/model/robloxmesh")
local tree = Rbx.tree()
local folder = Rbx.add(tree, Rbx.instance("Folder", "Parts"))
for i = 1, 20000 do
local p = Rbx.add(folder, Rbx.instance("Part", "P" .. i))
Rbx.set(p, "CFrame", "CFrame", { i, i % 7, -i, 1, 0, 0, 0, 1, 0, 0, 0, 1 })
Rbx.set(p, "size", "Vector3", { 4, 1, 2 + i % 3 })
Rbx.set(p, "Color3uint8", "Color3uint8", { i % 256, 128, 255 - i % 256 })
Rbx.set(p, "Anchored", "Bool", i % 2 == 0)
Rbx.set(p, "Transparency", "Float32", (i % 4) / 4)
Rbx.set(p, "Material", "Enum", 256)
end
local bin = Rbxm.encode(tree) :: buffer
local xml = Rbxmx.encode(tree) :: buffer
bench("rbxm decode (20k parts)", 3, buffer.len(bin), function()
Rbxm.decode(Bytes.reader(bin))
end)
bench("rbxm encode (20k parts)", 3, buffer.len(bin), function()
Rbxm.encode(tree)
end)
bench("rbxmx decode (20k parts)", 3, buffer.len(xml), function()
Rbxmx.decode(Bytes.reader(xml))
end)
local M = require("@tests/gen/robloxmesh")
local mesh = buffer.fromstring(M.cases[#M.cases - 1].data)
bench("robloxmesh decode (v7, skinned)", 20, buffer.len(mesh), function()
RobloxMesh.decode(Bytes.reader(mesh))
end)
end
do
local Brotli = require("@formats/codecs/compress/Brotli")
local BB = require("@tests/gen/brotli_bench")
@@ -1098,3 +1145,81 @@ do
end
end
end
do
-- NBT / voxels (ws-voxel): a chunk-like NBT tree (24 sections with packed long arrays, 4000 entity-like compounds)
-- through codecs/text/Nbt (binary and SNBT), 1M packed 5-bit indices, a 64^3 Sponge schematic and Qubicle file
local Nbt = require("@formats/codecs/text/Nbt")
local Mc = require("@formats/codecs/model/Minecraft")
local Schematic = require("@formats/model/schematic")
local Qb = require("@formats/model/qb")
local sections = Nbt.list("compound")
for s = 1, 24 do
local pal = Nbt.list("compound")
for p = 1, 16 do
table.insert(pal, Nbt.compound({ Name = "minecraft:block_" .. p, Properties = Nbt.compound({ axis = "y" }, { "axis" }) }, { "Name", "Properties" }))
end
local longs = buffer.create(256 * 8)
for i = 0, 511 do
buffer.writeu32(longs, i * 4, (i * 2654435761) % 4294967296)
end
table.insert(sections, Nbt.compound({ Y = Nbt.byte(s - 5), block_states = Nbt.compound({ palette = pal, data = Nbt.longArray(longs) }, { "palette", "data" }) }, { "Y", "block_states" }))
end
local ents = Nbt.list("compound")
for i = 1, 4000 do
table.insert(ents, Nbt.compound({
id = "minecraft:thing",
Pos = Nbt.list("double", { Nbt.double(i * 0.5), Nbt.double(64), Nbt.double(-i * 0.25) }),
Health = Nbt.float(20),
UUID = Nbt.intArray({ i, -i, i * 3, 7 }),
Tags = Nbt.list("string", { "a", "b" }),
Age = Nbt.short(i % 1000),
Seed = Nbt.long(i * 1234567),
}, { "id", "Pos", "Health", "UUID", "Tags", "Age", "Seed" }))
end
local root = Nbt.compound({ DataVersion = 3953, sections = sections, entities = ents }, { "DataVersion", "sections", "entities" })
local raw = assert(Nbt.encode(root, { compression = "none" }))
bench("nbt decode (" .. buffer.len(raw) // 1000 .. " KB)", 5, buffer.len(raw), function()
Nbt.decode(raw)
end)
bench("nbt encode", 5, buffer.len(raw), function()
Nbt.encode(root, { compression = "none" })
end)
local text = assert(Nbt.print(root))
bench("snbt parse (" .. #text // 1000 .. " KB)", 3, #text, function()
Nbt.parse(text)
end)
bench("snbt print", 3, #text, function()
Nbt.print(root)
end)
local n = 1048576
local idx = buffer.create(n * 2)
for i = 0, n - 1 do
buffer.writeu16(idx, i * 2, (i * 7) % 32)
end
local packed = Mc.Packed.pack(idx, n, 5, false)
local out = buffer.create(n * 2)
bench("packed unpack 1M x 5 bits (MB out)", 5, n * 2, function()
Mc.Packed.unpack(packed, 5, n, false, out, 32)
end)
local V = 64
local states = { "minecraft:air" }
for i = 1, 40 do
table.insert(states, "minecraft:block_" .. i)
end
local cells = buffer.create(V * V * V * 2)
for i = 0, V * V * V - 1 do
buffer.writeu16(cells, i * 2, if (i // V) % 3 == 0 then 0 else 1 + (i // 97) % 40)
end
local grid = Mc.voxels(V, V, V, states, cells)
local schem = assert(Schematic.encode(grid, { compression = "none" }))
bench("schem decode 64^3 (MB of cells)", 3, V * V * V, function()
Schematic.decode(Bytes.reader(schem))
end)
bench("schem encode 64^3", 3, V * V * V, function()
Schematic.encode(grid, { compression = "none" })
end)
local qb = assert(Qb.encode(grid))
bench("qb decode 64^3 rle (MB of cells)", 3, V * V * V, function()
Qb.decode(Bytes.reader(qb))
end)
end