mesecons icon indicating copy to clipboard operation
mesecons copied to clipboard

optimize mvps_push_or_pull

Open lolbinarycat opened this issue 1 year ago • 6 comments

this function is a big bottleneck, since it contains several layers of nested loops, and has quite a few allocations in the innermost levels.

i did my best to optimize it, and i'm only confident in about half my changes, although some imprecice testing implied as much as a 10x speedup.

if someone could benchmark this properly and see what changes are worth it, that would be greatly appreciated.

lolbinarycat avatar Dec 17 '23 21:12 lolbinarycat

apperently the CI uses a different lua version than minetest 5.7

since it lacks table.move.

not sure what to make of that

lolbinarycat avatar Dec 17 '23 21:12 lolbinarycat

table.move was added in Lua 5.3 and appears to be supported as a non-standard extension in LuaJIT. You can't use it.

sfan5 avatar Dec 17 '23 22:12 sfan5

LuaJIT adds table.move. You can check at load if it exists, and implement add_list without it if it's not there.

Desour avatar Dec 19 '23 17:12 Desour

all this code review is nice, but what would really be helpful is for someone benchmark this to see if the speedup is worth me fixing everything up.

or if someone could point me in the direction of some lua/minetest benchmarking tools i could try to do it myself.

my limited testing was based off of realtime and framerate, both of which can be influenced by other processes.

lolbinarycat avatar Dec 25 '23 17:12 lolbinarycat

Minetest has an internal profiler:

  • Settings to enable it: https://github.com/minetest/minetest/blob/335af393f09b3629587f14d41a90ded4a3cbddcd/builtin/settingtypes.txt#L1734-L1762
  • Chat command to export: https://github.com/minetest/minetest/blob/335af393f09b3629587f14d41a90ded4a3cbddcd/builtin/profiler/init.lua#L45-L46

According to mesecons/actionqueue.lua, the actions are executed each globalstep, thus you should see a difference in one of the mesecons -> globalstep[??] entries after running /profiler save txt (for comparison). I however do not know what the best way to test this optimization would be - 100 pistons with sand on top of them?

SmallJoker avatar Dec 27 '23 08:12 SmallJoker

Minetest has an internal profiler:

* Settings to enable it: https://github.com/minetest/minetest/blob/335af393f09b3629587f14d41a90ded4a3cbddcd/builtin/settingtypes.txt#L1734-L1762

* Chat command to export: https://github.com/minetest/minetest/blob/335af393f09b3629587f14d41a90ded4a3cbddcd/builtin/profiler/init.lua#L45-L46

According to mesecons/actionqueue.lua, the actions are executed each globalstep, thus you should see a difference in one of the mesecons -> globalstep[??] entries after running /profiler save txt (for comparison). I however do not know what the best way to test this optimization would be - 100 pistons with sand on top of them?

personally i used stacks of slimeblocks on top of sticky pistons connected to a 1-tick clock.

lolbinarycat avatar Dec 27 '23 22:12 lolbinarycat