OnTick questions

Place to get help with not working mods / modding interface.
Post Reply
cyfrov
Inserter
Inserter
Posts: 25
Joined: Thu May 03, 2018 7:09 pm
Contact:

OnTick questions

Post 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?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: OnTick questions

Post by DaveMcW »

I recommend using /measured-command to find the answer yourself.

Post Reply

Return to “Modding help”