I am currently working on a massive modernization overhaul of one of my classic games. Things are going well for the most part…
Except when it comes to lag.
I have improved a lot of performance issues. I had an issue where I was running GetDescendants() through a Heartbeat connection, which made lag/ping/compute efficacy absolutely awful. I optimized it, where the connection only had to run through 10 or so objects to find the 20 targets instead of running through thousands of objects, and I put a limiter on the Heartbeat connection, that the code is only executed once DeltaTime adds up to 1 or more seconds, and then is reset.
However, there are still noticeable lag spikes when someone leaves/rebirths, and their old tycoon is deleted, and a new one is generated. I attempted to mitigate this by sending the old tycoon model to be deleted via this way:
storage.deleteMe.ChildAdded:Connect(function(child: Instance)
for _,i in pairs(child:GetChildren()) do
if i:IsA("Folder") then
for _,v in pairs(i:GetChildren()) do
v:ClearAllChildren()
task.wait()
end
task.wait()
end
end
task.wait()
child:Destroy()
end)
However, that doesn’t really fix the issue much. The game is huge, uses about 4000x4000 of terrain, and has 22 tycoons in a server of 22 people with 11 teams. Ping can be as low as 20-30ms when the game starts up, but as the server fills up and/or gets older, ping usually hangs around 150-250ms.
It will climb up to 300-500+ms when someone leaves/rebirths. The spike is pretty short, but it can be noticeable sometimes. I’ve been keeping an eye on ping all day, and I’ve seen it spike a lot, but the players I play with generally tell me they don’t notice anything.
FWIW, I use StreamingEnabled, client memory usage starts out at 1900mb and slowly climbs up over time (as I type this, I’ve been playing for well over an hour, and I’m at 2600mb usage), server memory usage usually hangs around 2000-2500mb consistently, but tends to climb as well.
I’m wondering what ways some other tycoon developers here use to generate/delete/reset their tycoons without causing crazy lag spikes. Does anyone know of any?