● Based on my investigation, here's an analysis of migrating to LuaJIT:
Current State
Lua 5.3.6 bundled in src/lua/, using Sol2 v3.3.0 bindings. Lua is exclusively for modding API (22 hooks like on_game_load, on_shoot, etc.) - NOT core game logic. ~5k lines of mod scripts exist.
LuaJIT Benefits
Performance: LuaJIT is 3-5x faster than Lua 5.3 in most benchmarks:
- DNS benchmark: LuaJIT 2.1 (0.81s) vs Lua 5.4.2 (3.69s)
- JIT compilation provides significant speedup for computation-heavy code
- Better FFI for C interop (though not currently used)
Sources:
- https://github.com/Jipok/Lua-Benchmarks
- https://github.com/DNS/benchmark-language
- https://luajit.org/performance.html
Technical Feasibility
✅ Low Risk:
- Sol2 v3.3.0 already has extensive LuaJIT support (detected at src/sol/sol.hpp:2968-3002)
- All existing mod scripts use vanilla Lua 5.3 - no incompatibilities
- No FFI, bit ops, or LuaJIT-specific features in use
⚠ Changes Required:
- Build system (src/lua/CMakeLists.txt): Replace bundled Lua with LuaJIT library
- Sol2 config: May need to adjust SOL_ALL_SAFETIES_ON (currently prioritizes safety over speed)
- Testing: Validate all 22 hooks + existing mod scripts
- C++ compilation mode: LuaJIT prefers C mode; current config uses SOL_BUILD_CXX_MODE
Should You Migrate?
❌ Probably NOT worth it for this project:
Reason 1 - Limited impact: Lua only runs optional mod hooks, not core game loop. Performance gain would only affect:
- Mod script execution (infrequent events like on_mapgen_postprocess)
- Not rendering, pathfinding, or simulation (all C++)
Reason 2 - Maintenance cost:
- LuaJIT is based on Lua 5.1 (not 5.3) - API differences exist
- LuaJIT development is less active (Lua 5.4+ features unavailable)
- Would need to maintain LuaJIT dependency instead of bundled source
Reason 3 - No documented performance issues: No evidence mod scripts are slow enough to warrant migration.
✅ ONLY migrate if:
- Mods become computationally intensive (heavy procedural generation, complex AI)
- Performance profiling shows Lua is a bottleneck
- You want FFI access for mods (advanced use case)
Recommendation
Stay with Lua 5.3.6 unless profiling reveals mod script performance issues. The 3-5x speedup wouldn't meaningfully impact overall game performance since Lua execution is already minimal compared to C++ game logic.
If performance becomes critical later, migration path is straightforward due to Sol2's existing LuaJIT support.