Files
moonwell-client-core/crates/benilla-lua/examples/callbench.rs
T
Mathih13 8100fe9820 Run the script host on benilla-lua; remove the vendored C Lua and mlua (#1255)
The script host now runs on benilla-lua alone. The vendored C Lua 5.1.5 (`third_party/lua-src`) and mlua are removed, about 17k lines. `vm_parity` checks benilla-lua against the answers the C build recorded on Linux and macOS, and `front_end` checks every corpus chunk's compiled shape against the C build's digest. `GRAMMAR.md` records each grammar change from 5.1, by client address.

A handler's `this`, `event` and `arg1`… are bound in one VM call. An event fire saves and restores `event`, while the handler runner saves only `this` (`0x704d50`).

Ours on the branch: VM fixes from review (hook dispatch counts, registers and frames around a collection, protected-call handlers, library errors) and `vm_parity`'s two-VM leftovers removed.

Tests: the full gate chain on the merged tree, `vm_parity` and `front_end` among them. Live: smoke and a stock-glue login. Load time is level with C Lua, and memory is within 7%.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Sam <samuv.eth@gmail.com>
2026-10-17 08:51:37 +07:00

37 lines
1.4 KiB
Rust

//! Call micro-benchmarks, best of five.
use std::time::Instant;
const CASES: &[(&str, &str)] = &[
("empty call", "local function f() end for i = 1, 3000000 do f() end"),
("arg+ret", "local function f(x) return x end local s = 0 for i = 1, 3000000 do s = s + f(i) end"),
("upvalue call", "local f f = function(x) return x end local function g() local s = 0 for i = 1, 3000000 do s = s + f(i) end return s end g()"),
("method", "local C = {} C.__index = C function C:m() return self end local o = setmetatable({}, C) for i = 1, 3000000 do o:m() end"),
("method on self", "local o = {} function o:m() return self end for i = 1, 3000000 do o:m() end"),
("loop only", "local s = 0 for i = 1, 3000000 do s = s + i end"),
];
fn best<F: FnMut()>(mut f: F) -> f64 {
(0..5)
.map(|_| {
let t = Instant::now();
f();
t.elapsed().as_secs_f64() * 1e3
})
.fold(f64::MAX, f64::min)
}
fn main() {
if let Some(only) = std::env::args().nth(1) {
let src = CASES.iter().find(|c| c.0.contains(&only)).unwrap().1;
for _ in 0..20 {
let mut vm = benilla_lua::new_state();
vm.exec(src.as_bytes(), b"=b").unwrap();
}
return;
}
for (name, src) in CASES {
let ours = best(|| {
let mut vm = benilla_lua::new_state();
vm.exec(src.as_bytes(), b"=b").unwrap();
});
println!("{name:<16} {ours:6.2} ms");
}
}