[0.17.41] Performance issues with get_craftable_count
Posted: Mon May 20, 2019 2:34 am
Hi,
While investigating some performance issues in the Handyhands mod (https://mods.factorio.com/mod/HandyHand ... 000c4ed671), I discovered that the player.get_craftable_count API seems to be taking a lot of time to run when mods with lots of recipes are installed, but it doesn't make a lot of sense as to why. Specifically, this code:
Takes around 2-3ms to run when a full set of Pyanodon's mods are installed. More complex recipes or more checks per frame can easily drive the costs to 50ms or more, which obviously causes stuttering. When you think about it, this doesn't make a lot of sense - the recipe for a pipe has not changed at all due to the mods - it's still just 1 iron plate, and there aren't really any recipes for handcrafting iron plates. Since Pyanodon's mods (and most other big mods) add large iron plate refining recipe chains, it's probably wandering through those uncraftable recipe chains and collecting the ingredients? Or is it just an unavoidable problem with a lot of recipes?
So a couple things:
1. Is the get_craftable_count API call looking through un-hand-craftable recipes? Can it not do that?
2. Presumably the inventory does things a bit differently, since it doesn't take several seconds to load. Can we get access to whatever it's doing to get recipe counts in a mod?
While investigating some performance issues in the Handyhands mod (https://mods.factorio.com/mod/HandyHand ... 000c4ed671), I discovered that the player.get_craftable_count API seems to be taking a lot of time to run when mods with lots of recipes are installed, but it doesn't make a lot of sense as to why. Specifically, this code:
Code: Select all
script.on_event(
defines.events.on_tick,
function(event)
local p = game.players[1]
local craftableCount = p.get_craftable_count("pipe")
end
)
So a couple things:
1. Is the get_craftable_count API call looking through un-hand-craftable recipes? Can it not do that?
2. Presumably the inventory does things a bit differently, since it doesn't take several seconds to load. Can we get access to whatever it's doing to get recipe counts in a mod?