[1.1.38] spill_item_stack causes heavy lag
Posted: Sun Sep 05, 2021 7:57 am
the command spill_item_stack() causes unnecessarily heavy lag due to needing to find where to drop repeatedly.
this is shown in the following example
on my machine the following code takes 2 seconds.
/c player = game.player
for i=1,1 do
player.surface.spill_item_stack({0, 0}, {name="iron-plate", count=100000}, true, player.force, true)
end
while this code takes 16 seconds.
/c player = game.player
for i=1,1000 do
player.surface.spill_item_stack({0, 0}, {name="iron-plate", count=100}, true, player.force, true)
end
both have identical results but the 2nd is divided into stacks of 100
this is important due to the most common use case looking something like this, going through an inventory and spilling everything on the same location.
for i=1,#inventory do
if inventory.valid_for_read then
player.surface.spill_item_stack(player.position, inventory, true, player.force, true)
inventory.count = 0
end
end
(code from https://mods.factorio.com/mod/muppet_streamer)
this is far closer to the slow case and so takes a long time.
this is shown in the following example
on my machine the following code takes 2 seconds.
/c player = game.player
for i=1,1 do
player.surface.spill_item_stack({0, 0}, {name="iron-plate", count=100000}, true, player.force, true)
end
while this code takes 16 seconds.
/c player = game.player
for i=1,1000 do
player.surface.spill_item_stack({0, 0}, {name="iron-plate", count=100}, true, player.force, true)
end
both have identical results but the 2nd is divided into stacks of 100
this is important due to the most common use case looking something like this, going through an inventory and spilling everything on the same location.
for i=1,#inventory do
if inventory.valid_for_read then
player.surface.spill_item_stack(player.position, inventory, true, player.force, true)
inventory.count = 0
end
end
(code from https://mods.factorio.com/mod/muppet_streamer)
this is far closer to the slow case and so takes a long time.