Page 1 of 1

OnTick questions

Posted: Mon Jan 07, 2019 7:40 pm
by cyfrov
One of the big notes I've taken away from the mod documentation is to minimize the amount of processing workload in any OnTick event handlers.
...but there are still things that need to be done on a tick, and fast.

So I guess a few questions are necessary to help better understand the tradeoffs.

LuaJIT? - the forums are still unclear on this, some posts show that this has been on the radar since 0.13, but the PDB file doesn't include any jit references, so I'm unsure if it's implemented.
Consequence: besides the obvious speed boost, jitting would make sloppy coding less of a problem.
i.e. A lot of mods do something like:

Code: Select all

function OnTick() 
 if (cond)
    {do something...long body}
 end
end
without dynamic optimization, the better way to write that, should be:

Code: Select all

function OnTick()
 if not (cond)
  return
 end
 {do something...long body}
end
...if it's not immediately obvious why that makes a difference, chances are you need to re-read your compilers and processors textbooks.

-----------------------

Map/Dictionaries - when doing a static key access to a map, is there any internal optimization for the access?
how is something like this handled?

Code: Select all

game.item_prototypes['my-object']
Does the factorio version of lua pre-parse the script file and with static instances like that, substitute a direct pointer to the object? or does that take 3 hashmap accesses?

Re: OnTick questions

Posted: Mon Jan 07, 2019 10:56 pm
by DaveMcW
I recommend using /measured-command to find the answer yourself.