Hello!
A recent update in SE results in far-away chunks being deleted often (during each meteor hit). This causes lag-spikes when run with Stack Combinator. I had a look as to why, and it seems you are doing quite a lot of computations during on_chunk_deleted, doing two find_entities_filtered
on every surface.
There's lots of ways to optimize it of course, but the simplest would be to change
events.register(defines.events.on_chunk_deleted, purge)
to (untested)
events.register(defines.events.on_chunk_deleted, function(event)
local surface = game.get_surface(event.surface_index)
for _, chunk_position in pairs(event.positions) do
if surface.is_chunk_generated(chunk_position) then
purge()
return
end
end
end)
This works because the chunk SE deletes isn't fully generated. And it can't contain any entities if it's not fully generated.
Or even easier, don't do the check at all :P