Skip to content

build(benchmarks): add setup_luaport.sh to build luaport against lua@5.4#225

Merged
davydog187 merged 1 commit into
mainfrom
bench-luaport-setup-script
May 21, 2026
Merged

build(benchmarks): add setup_luaport.sh to build luaport against lua@5.4#225
davydog187 merged 1 commit into
mainfrom
bench-luaport-setup-script

Conversation

@davydog187
Copy link
Copy Markdown
Contributor

Why

mix deps.compile luaport fails on a stock brew install lua setup, even with PKG_CONFIG_PATH set. Two reasons:

  1. Wrong Lua version. brew install lua ships Lua 5.5; luaport 1.6.3 supports only LuaJIT or Lua 5.4. Its Makefile pkg-configs luajit by default.
  2. API drift. Even against Lua 5.4, deps/luaport/c_src/luaport.c:517 uses LUA_GLOBALSINDEX, which Lua removed in 5.2.

PKG_CONFIG_PATH alone can't fix either — DEFINES := … in the luaport Makefile uses := so the LuaJIT-only LUAP_BIT/LUAP_FFI flags can't be overridden from the env, and the LUA_GLOBALSINDEX issue is in C source.

What

  • benchmarks/setup_luaport.sh — idempotent shell script that:
    • locates Homebrew's lua@5.4 prefix,
    • patches deps/luaport/Makefile to pkg-config lua-5.4 (Homebrew's package name) and drop the LuaJIT-only LUAP_BIT/LUAP_FFI defines,
    • patches deps/luaport/c_src/luaport.c to replace the single LUA_GLOBALSINDEX use with lua_pushglobaltable + lua_rawset(L, -3),
    • runs MIX_ENV=benchmark mix deps.compile luaport --force.
  • benchmarks/{closures,fibonacci,oop,string_ops,table_ops}.exs — updated the # NOTE: header in all five files to point at the new one-liner workflow.

Workflow now

brew install lua@5.4
./benchmarks/setup_luaport.sh
MIX_ENV=benchmark mix run benchmarks/fibonacci.exs

Verification

Ran the full clean cycle (mix deps.clean luaport → mix deps.get → ./benchmarks/setup_luaport.sh) and then each of the five benchmarks. All five now show a C Lua (luaport) column. Re-running the script on an already-patched tree is a no-op (guarded by grep on the use site, not the explanatory comment).

Fibonacci result for reference:

C Lua (luaport)   38.51 ips    25.97 ms
luerl              1.40 ips   716.84 ms    27.61x slower
lua (eval)         1.16 ips   859.34 ms    33.09x slower
lua (chunk)        1.15 ips   869.29 ms    33.48x slower

Caveat

The patches live under deps/luaport/, which mix deps.clean luaport will wipe. The script is idempotent, so the workflow after any deps churn is just ./benchmarks/setup_luaport.sh. A more durable fix would be a forked luaport on a branch, but that adds a fork to maintain. Happy to do that if preferred.

luaport 1.6.3 ships a Makefile that pkg-configs LuaJIT by default and uses
LUA_GLOBALSINDEX (removed in Lua 5.2) in c_src/luaport.c. Neither is
overridable from the env — DEFINES is assigned with := and the source
issue is in C — so 'mix deps.compile luaport' fails on a stock Homebrew
install regardless of PKG_CONFIG_PATH.

Add benchmarks/setup_luaport.sh: an idempotent shell script that

  - locates Homebrew's lua@5.4 prefix,
  - patches deps/luaport/Makefile to pkg-config lua-5.4 and drop the
    LuaJIT-only LUAP_BIT / LUAP_FFI defines,
  - patches deps/luaport/c_src/luaport.c to replace the single
    LUA_GLOBALSINDEX use with lua_pushglobaltable + lua_rawset(L, -3),
  - runs 'mix deps.compile luaport --force'.

Update the # NOTE: header in all five benchmark .exs files to point at
the new one-liner workflow instead of the old PKG_CONFIG_PATH
incantation, which never worked on its own.

Patches live under deps/luaport/ so 'mix deps.clean luaport' will wipe
them; re-running the script is a no-op on an already-patched tree, so
the workflow is just './benchmarks/setup_luaport.sh' after any deps
churn.
@davydog187 davydog187 merged commit 34cff99 into main May 21, 2026
4 checks passed
@davydog187 davydog187 deleted the bench-luaport-setup-script branch May 21, 2026 21:09
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