Skip to content

perf(vm): drop +16 register buffer on interpreter :call path #312

Closed

Description

@davydog187

Context

Fibonacci (recursive) is 1.18× slower than luerl (1.23s vs 1.04s in
benchmarks/fibonacci.exs).

Internal signal: benchmarks/dispatcher_vs_interpreter.exs shows the
dispatcher path running fib(25) 1.20× faster than the interpreter. The
dispatcher allocates exactly max(max_registers, param_count) per frame
(lib/lua/vm/dispatcher.ex:1375-1381); the interpreter allocates +16
extra slots
per frame (lib/lua/vm/executor.ex:978-979):

```elixir
callee_regs =
Tuple.duplicate(nil, max(callee_proto.max_registers, param_count) + 16)
```

For fib(28) (~1.4M frames), those 16 extra slots per frame are pure
allocation churn.

Change

lib/lua/vm/executor.ex:978-979.

Audit the call sites that historically required the buffer (multi-return
inline expansion into the callee's register window). Then either:

a) Prove codegen reports honest peak register usage (matching the
dispatcher's codegen contract) and remove the buffer entirely.
b) Keep a much smaller buffer (2–4) gated on is_vararg / known
multi-return callees only.

The dispatcher already runs with no buffer, which establishes the safety
argument for at least the dispatcher-eligible subset.

Verification

  • Full mix test — miss-sized callee tuples manifest as runtime errors,
    not static failures.
  • Lua 5.3 official suite runner (whatever script is canonical).
  • mix run benchmarks/fibonacci.exs
  • mix run benchmarks/dispatcher_vs_interpreter.exs — gap should close,
    not invert.

Expected

Noticeable share of the 1.18× fib gap and the closures-benchmark gap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:perfPerformance change

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions