Skip to content

bench: add a host-call kernel - #320

Merged
siyul-park merged 2 commits into
mainfrom
bench/host-call
Nov 10, 2026
Merged

siyul-park merged 2 commits into
mainfrom
bench/host-call

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Summary

docs/roadmap.md P1 lists host calls as a benchmark area; no kernel covered it.

  • host-call: acc = mix(acc, i) for i < 1024, where mix(a, b) = (a*31 + b) % 1000003 is a Go function each runtime calls once per iteration.
  • registry.Spec.Host (Name, I32 func(a, b int32) int32): a plain Go func, so the fixture source needs no runtime import (Yaegi evaluates it).
  • minivm binds it through the documented default path, Interpreter.Marshal → Alloc → SetGlobal(0) (.mvm declares global 0 with the func type and calls global.get 0; call). Reset reseeds globals, so the runner re-binds after each Reset, outside both the timed and the allocation-sampling windows.
  • Tengo UserFunction, GopherLua NewFunction, Goja Set, gpython module global. CPython runs out of process and is skipped; Yaegi and native run the Go source.

Finding (local, M4 Pro, 300 ms)

runtime per call allocs/op
threaded ~369 ns 14073
jit ~311 ns 14073
gpython ~47 ns 1799
GopherLua ~57 ns 1079
Tengo ~83 ns 3073
native Go ~3 ns 0

The codec's Marshaled func costs ~13.7 allocations per call. Tracked as a follow-up in the maintainer's queue (host-call optimization).

Review

Independent Opus review: approve. Fixtures identical and int32-safe, Marshal/Alloc/SetGlobal ownership balanced across Reset cycles, setup outside measurement, every other kernel's script runners still pass. Applied: Host doc states how minivm binds (global 0), README CPython count. Not applied: argument checks in the gpython/Tengo bindings (diagnostics only; a wrong call cannot happen with these fixtures).

Validation

  • go test ./... in benchmarks/, make check, git diff --check

🤖 Generated with Claude Code

roadmap.md lists host calls as a P1 benchmark area, and no kernel
covered it. host-call loops 1024 times over acc = mix(acc, i), where
mix is a Go function every runtime calls once per iteration.

registry.Spec gains Host, a plain Go func, so the fixture source stays
free of runtime imports for Yaegi. minivm binds it the documented
default way, Interpreter.Marshal -> Alloc -> SetGlobal(0), again after
each Reset because Reset reseeds globals, outside the timed window.
Tengo, GopherLua, Goja and gpython bind it as a global function; CPython
runs out of process and is skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 03a98e0d-4a32-4b72-bce7-c317ad268533
Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@siyul-park
siyul-park merged commit 4f77b90 into main Nov 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant