I and a friend of mine were developing mods and testing mod compatibility alongside this mod, and we discovered that Checking consistency stage of the game takes unusually long time. It took me more than half a minute, and for my friend, several minutes.
I backtraced the game and found that it is due to this mod's script.on_configuration_changed, in particular, these lines:
for _, t in ipairs(s.find_tiles_filtered{name = "out-of-map", has_hidden_tile = true}) do
if t.hidden_tile == "grass-1" then
s.set_hidden_tile(t.position, substitute)
found = true
end
end
I tried to get timing info, using
@@ -117,12 +117,19 @@ script.on_configuration_changed(function(config) -- TBC
found = true
end
s.set_tiles(new_tiles)
+ print('before find_tiles_filtered')
+ local i = 0
for _, t in ipairs(s.find_tiles_filtered{name = "out-of-map", has_hidden_tile = true}) do
+ if i == 0 then
+ print('first iteration')
+ end
+ i = i + 1
if t.hidden_tile == "grass-1" then
s.set_hidden_tile(t.position, substitute)
found = true
end
end
+ print('end', i, 'iteration')
end
if found then game.print("[font=default-large-bold][color=yellow]Subsurface: At least one tile generated in subsurfaces was removed from the game due to your mod configuration c
hanges. It has been replaced with dirt-like tiles.[/color][/font]") end
end)
and this is the output:
Dec 20 02:04:36 before find_tiles_filtered
Dec 20 02:04:44 first iteration
Dec 20 02:04:45 end 3043007 iteration
Dec 20 02:04:45 before find_tiles_filtered
Dec 20 02:04:53 first iteration
Dec 20 02:04:54 end 2655697 iteration
Dec 20 02:04:54 before find_tiles_filtered
Dec 20 02:05:01 first iteration
Dec 20 02:05:01 end 2330559 iteration
Dec 20 02:05:01 before find_tiles_filtered
Dec 20 02:05:09 first iteration
Dec 20 02:05:10 end 3814948 iteration
Dec 20 02:05:10 before find_tiles_filtered
Dec 20 02:05:10 first iteration
Dec 20 02:05:10 end 760272 iteration
Dec 20 02:05:10 before find_tiles_filtered
Dec 20 02:05:11 first iteration
Dec 20 02:05:11 end 833028 iteration
Dec 20 02:05:11 before find_tiles_filtered
Dec 20 02:05:11 first iteration
Dec 20 02:05:11 end 50625 iteration
As I understand out-of-map is for chunks that have been generated, but not revealed by mining the neighboring rocks. However, Factorio slowly generates a square of 39x39 chunks around the player, with player in the center; you can see this with show-generated-chunks debug option. (39x39 is only entity-generating chunks; the tile-generating chunk diameter is even larger, but I'm not sure by how much.) With each chunk being 32x32 tiles, assuming a player has stayed in a level for a while but didn't explore, this would be 1,557,504 tiles per layer. And if we want to get the 300% natural prod, we'd have around 11 layers for a total of 17,132,544 tiles.
Not only that the Lua code has to go though millions of iterations, Factorio also needs to construct these millions of tile objects and add them into a resizable data structure to be returned to the Lua code.
Is this loop really necessary? If so, can it be optimized (say, by sampling)?