Initial commit

This commit is contained in:
Mikita Wiśniewski 2025-02-10 22:34:42 +07:00
commit 9410a2bcd5
7 changed files with 105 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.swp
*.patch
*.bak

3
.luacheckrc Normal file
View file

@ -0,0 +1,3 @@
read_globals = {
"core", "jit"
}

10
LICENSE Normal file
View file

@ -0,0 +1,10 @@
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

47
README.md Normal file
View file

@ -0,0 +1,47 @@
# Tune JIT `tune_jit`
A Luanti mod tuning LuaJIT parameters to improve server performance by
preventing constant GC.
## Wait, what does it exactly do?
At a base level, this mod implements the same thing as [VoxeLibre](https://git.minetest.land/VoxeLibre/VoxeLibre/src/commit/161dbaea03a7816db1393ca767c84a5f275ef162/mods/CORE/mcl_init/tune_jit.lua)
and [Mineclonia](https://codeberg.org/mineclonia/mineclonia/src/commit/94467d9f822ae31838e3c76d643950be2ee891f8/mods/ENTITIES/mcl_mobs/pathfinding.lua#L1627-L1636)
but for other Luanti games, with more configurability for the server operator.
[The `jit.opt.*` API](https://luajit.org/ext_jit.html) is leveraged in order to
modify JIT compiler optimization parameters on server startup. This won't work
with LuaJIT 1.x, but if you have a LuaJIT that ancient, most of your server-side
performance issues should go away after you upgrade it. The coolest thing is
that this mod doesn't have to be in the `secure.trusted_mods` list in order to
apply the parameters.
In [@halon](https://codeberg.org/halon)'s words:
> Large minetest servers on stock luajit spend most of their globalsteps
> recording and jit compiling traces that are evicted for exceeding one of the
> minuscule limits on trace count or mcode size defined by default
The specific parameters that are modified are `maxtrace`, `maxrecord`,
`minstitch` and `maxmcode`. Please refer to this mod's `settingtypes.txt` and
LuaJIT documentation for details.
## Will it help with client-side lag?
Unless it was the server's fault, no.
For singleplayer, remember that Luanti just starts up a server under the hood
and connects you to it, with the same server/client communication rules and
specifics. The only difference is that both server and client are now ran on the
same machine, though most likely in different threads.
Mobs freezing and map generation suddenly stopping might get removed, but this
won't have any effect on rendering or audio playback.
## License
The source code is licensed under 0BSD ("public domain"). See `LICENSE` file for
details.

23
init.lua Normal file
View file

@ -0,0 +1,23 @@
if not core.global_exists("jit") then
core.log("warning", "[tune_jit] Couldn't find LuaJIT, nothing to tune")
return
elseif not jit.status() then
core.log("warning", "[tune_jit] LuaJIT is enabled but JIT compiler is disabled")
return
end
local PARAM_DEFAULTS = {
maxtrace = 24000, -- 1000 for LuaJIT; 8000 for OpenResty
maxrecord = 32000, -- 4000 for LuaJIT; 16000 for OpenResty
minstitch = 3, -- 0 for LuaJIT; 3 for OpenResty
maxmcode = 163840 -- 512 for LuaJIT (O_O); 40960 for OpenResty
}
local opt = {}
for name, default_value in pairs(PARAM_DEFAULTS) do
local value = tonumber(core.settings:get("tune_jit."..name)) or default_value
table.insert(opt, name .. "=" .. value)
end
jit.opt.start(unpack(opt))
core.log("action", "[tune_jit] Applied increased JIT compiler optimization parameters")

3
mod.conf Normal file
View file

@ -0,0 +1,3 @@
name = tune_jit
title = Tune JIT
description = Tunes LuaJIT parameters to improve server performance by preventing constant GC

16
settingtypes.txt Normal file
View file

@ -0,0 +1,16 @@
# Maximum amount of cached traces.
# 1000 for stock, 8000 for OpenResty
tune_jit.maxtrace (Max. # of traces in cache) int 24000 0
# Maximum amount of IR (Intermediate Representation) instructions.
# 4000 for stock, 16000 for OpenResty
tune_jit.maxrecord (Max. # of recorded IR instructions) int 32000 0
# Minimum amount of IR (Intermediate Representation) instructions to be
# included in a stitched trace.
# 0 for stock, 3 for OpenResty
tune_jit.minstitch (Min. # of stitched trace IR instructions) int 3 0
# Maximum total size of all machine code areas, in kilobytes.
# 512 for stock, 40960 for OpenResty
tune_jit.maxmcode (Max. machine code size) int 163840 0