Page 1 of 1

Runing Mod Operations in Compiled C++ or other Code

PostPosted: Thu Feb 04, 2016 19:44
by SegFault22
I am working on making a new kind of mod, where a lot of information has to be processed before doing any registry entries of items, tools, nodes, craft operations, etc. - you could say the information dictates the values of the properties that will be passed on to each registry entry.
Lua appears to take more time processing the information, which may cause problems if a large amount of information has to be processed and the machine is not fast enough to process it relatively quickly. For regular cases of usage, it should only take a second or so to process the information, even if it has been modified by a user to fit their will; however, it is possible for a user to "go wild" and add a very large amount of new items, which could cause the mod to take much more time for loading the information. It is foreseeable that a popular server could be created, using this mod to add many new materials into the game world environment; if such a server were caused to crash by some other mod's mishandling while some number of players are online, they would be abruptly disconnected and shown an error message. If the server is running with a script that automatically re-starts the server when it crashes or stops, the time spent loading the mod information could add a significant amount to the server downtime - users may believe that the server is going to "stay down", and go join another server or close the game just a few seconds before the server is back online and everyone else starts joining.

To avoid such a problem, it is in our best interest to reduce loading time for the mod, which could theoretically be done by using a different "program" to process the information and "return" the results to be used for making the registry entries through the Lua side via minetest.register_*(). I do not know much about how Minetest handles File Input/Output being run through Lua, specifically in what restrictions are applied when trying to run compiled code, so I figured that I should ask the forum and see if there are any security measures in place, for example, to prevent a third-party mod from running malicious code to cause a buffer overflow and nop-slide the memory register into even more malicious shell code. I know that some mods are compiled Lua and that it can run, but that does not count because it isn't a different programming language and it isn't potentially any faster.

In order to use another programming language for processing the information, there needs to be a way to get Minetest to run compiled code, which would then read the mod configuration files, process the information, and somehow "return" it to the Lua process which invoked it. Is this even possible?

Re: Runing Mod Operations in Compiled C++ or other Code

PostPosted: Wed Mar 16, 2016 06:47
by sofar
It's not the mod loading time that is the issue. Lua is extremely fast at loading, and all this happens server side in milliseconds. At most, even with a lot of mods, the server takes maybe 1-2 seconds to actually start.

The long login times are because people include hi-res textures, exotic 3d models and megabytes of custom sounds that need to be transferred 1-by-1 to each and every client at login time, plus thousands of node definitions, and those can not be cached by the client.

Actual execution of lua in mods is in the micro-second times, and completely a non-starter to optimize. Maybe there's a bad mod somewhere, but that is usually easily fixed. Abusive mods can bring any server down, so don't run a server if you don't know how to secure it and how to make it stable.