Page 2 of 2

Re: Opening the source?

Posted: Sun May 17, 2015 7:25 am
by sillyfly
The speed is highly dependent on the implementation of the Lua engine: as I said, luajit seems to do very well, in comparison to other Lua engines and in comparison to C and C++.

Take a look at this: http://luajit.org/performance_x86.html
Seems like luajit does up to 100+ times faster than normal Lua 5.1.5. I don't know which one is used in factorio, but that's a BIG difference!

Edit: Here's another page I found - https://attractivechaos.wordpress.com/2 ... by-luajit/ . For his test - the luajit performance was only 10% slower than C, which is very much comparable in speed.

Re: Opening the source?

Posted: Sun May 17, 2015 8:49 am
by quinor
Lua scripts usually have little impact on game performance, I talked with one of the devs about that quite recently. I also asked them if they'll move to luajit at some point, but according to what he said there is no need for that. Maybye in the future they'll do that, when mods/game will use much more Lua scripting.

Re: Opening the source?

Posted: Sun May 17, 2015 11:41 am
by tux_mark_5
psorek wrote:Lua scripts usually have little impact on game performance, I talked with one of the devs about that quite recently. I also asked them if they'll move to luajit at some point, but according to what he said there is no need for that. Maybye in the future they'll do that, when mods/game will use much more Lua scripting.
There are 2 reasons for that:
1. You can't do that many exciting things with current Lua API. As I mentioned before, the best you can do is to augment current entities to do something a bit different.
2. Most people who have written more than a few lines of code in their life probably can estimate, that the moment you start updating every instance of an entity in your mod every tick, the performance of such mods will go down so hard, so fast that people will eventually avoid your mod like a plague. While some minor entity updates might not cause such things to happen, but something more intensive, such as a complete belt replacement written in Lua would do exactly that. And that is why most major mods (again, in my personal opinion) just expand on the things we already have in the game (more assembler types, more roboport types, more ores, etc).

Re: Opening the source?

Posted: Sun May 17, 2015 11:45 am
by orzelek
psorek wrote:Lua scripts usually have little impact on game performance, I talked with one of the devs about that quite recently. I also asked them if they'll move to luajit at some point, but according to what he said there is no need for that. Maybye in the future they'll do that, when mods/game will use much more Lua scripting.
I'd tend to agree with some exceptions.
Currently when running shadows mod pack there is a heavy lag when bots build a lot of things in succession. I'm pretty sure it's caused by one of mods processing - I'm not sure which one exactly. So it's a lot of lua processing that causes this.
Same would also apply to treefarm mod easily - it's because it implements mechanic (tree growth) thats not present in base game.

Re: Opening the source?

Posted: Sun May 17, 2015 1:29 pm
by quinor
Orzelek: I'm quite sure that I could implement this particular treefarm feature - growing trees - in such way that it wouldn't lag at all. But still, implementing some features (like replacing entire belt system) is currently impossible to do with Lua using existing mod API.

Tux: Updating every entity every tick is always time-consuming, and no programming language will change that. The key is such optimalisation that you don't need to do it, and in most cases it can be done. I've been dealing with this class of problems for last 6 years and only rarely you are forced to use excessive amounts of raw computer power :)

Re: Opening the source?

Posted: Fri May 22, 2015 7:50 pm
by tux_mark_5
Small request to developers: would it be possible to link the next version of factorio on linux with -rdynamic flag? This would export all symbols in such a way that they can be accessed by the dynamic linker and so native factorio plugins could make use of factorio's internals. This way one could build a factorio plugin as a shared library and just add it to LD_PRELOAD list. This could also be mixed with source hotpatching to redirect native factorio method calls to some custom version of that function. I've been thinking of a way to provide native modding support for factorio and (at least for linux platforms) this appears to be the most straightforward way.

This method works even without -rdynamic flag, but it requires manual fiddling with factorio's binary (entries from .symtab need to be moved to .dynsym so plugins could dynamically link against factorio executable).

Also, after analyzing the debugging symbols in factorio I've found out that most interfaces (class names, members, member formal parameters, fields; for templates, their specializations, etc) can be "reassembled" purely out of DWARF debugging data that is stored within ELF binary. Combined with LD_PRELOAD method this allows to build fully functional native plugins for factorio.

Theoretically, similar approach should work on windows as well: all PE binaries (both exes and dlls) can have an export table that acts the same way as a .dynsym table in ELF binaries. Dlls into factorio executable can be injected by using a custom launcher/debugger or using remote thread creation (CreateRemoteThread). When a plugin/mod is loaded, entries marked with __declspec(dllimport) should be imported from factorio binary and thus made accessible to the plugin. Though at this point I am not 100% sure how new entries can be added to a regular executable's export table (it is possible that a simple declspec would work).

A cleaner way to handle this on both platforms would be to make factorio as a shared library on all platforms with extremely thin launcher executable, but this would require more severe changes in the way factorio is currently being built.

Re: Opening the source?

Posted: Sun Nov 03, 2019 6:15 pm
by rmusk
I know that this is an old thread, but isn't the freeplay part already "open-source"? It looks like only the engine is closed-source C++ code, and all the 'game' is written in Lua using the mod APIs.

But if I change the base mod, can I make the game completely different from vanilla?

Re: Opening the source?

Posted: Tue Mar 03, 2026 11:32 am
by Tamimbook
kovarex wrote: Sun Mar 24, 2013 3:12 am The main problem with open source is this.
I can imagine situation, where we spend 3 man/years of developing this game, and make it opensource, few people will add few things and suddenly, people will feel like this became some kind of "public property".
so what is they think it's a "public property" people still and forever appreciate your unique game! @kovarex you are thinking much this is not what people think these days I'm saying open-source is a way to have lots of PR and support of the game code contribution
anyways I wanted that the factorio would be open-source so I can clone and experiment on the game
hope you understand or not brother.....

Re: Opening the source?

Posted: Wed Mar 04, 2026 6:02 pm
by OBXandos
Arise thread. Thread arise!

I had to do a double take when I saw the thread dates...