I have a save which had the FPS suddenly (in the span of a couple hours, with no major changes to the map) go from 60 to 45. Most of that seemed to be spent on "render preparation" (the first of the three "preparation" entries in the debug "show time used" option).
.
Interestingly, it vanished entirely when in map view.
After some testing, I was able to confirm it to be the lights from my Bioluminescence mod, which uses LuaRendering.draw_light extensively (one tied to each generated glowing plant, of which there are a few per chunk, and one tied to every spawned biter/spitter).
Here is where what I believe is a bug comes in: LuaRendering.clear() removes the lag - FPS immediately returns to 60 - but killing the entities with script/commands does not, even though the lights are removed when their parent entities are:
Further cementing this, using rendering.clear() and then re-creating the lights anew does NOT bring back the lag; FPS is reasonably stable around 60.
This strongly implies that lights created via LuaRendering have some computational overhead that persists even after they are culled through the removal of their parent entity.
This overhead persists across save-load and game reboot cycles. Something tells me the "Each render object is identified by an id that is universally unique for the lifetime of a whole game." in the LuaRendering docs is related.
In the case of my mod, my guess is that the lights tied to biters continued to accumulate this overhead, as there is a near infinite stream of new biters, and removing (ie killing) the old ones did not clear the overhead from their lights.
For now, I will just periodically flush the rendering cache and create new ones, but given that that too probably has potential issues, I would very much prefer if the underlying problem here was resolved.
In case it helps, here is the source of the mod in question, and I have attached the save file. The commands I ran to test were:
- /c for _,e in pairs(game.surfaces[1].find_entities_filtered{type = {"tree", "simple-entity"}}) do e.destroy() end
/c rendering.clear("Bioluminescence")
Here is a command to recreate new lights (with incorrect colors, but who cares for testing purposes) and see that the lag does not return:
/c for _,e in pairs(game.surfaces[1].find_entities_filtered{type = {"tree", "simple-entity"}}) do if string.find(e.name, "glowing", 1, true) then rendering.draw_light{sprite="utility/light_medium", scale=0.5, intensity=1, color={r = 1, g = 1, b = 0, a = 1}, target=e, surface=e.surface} end end