In one of my games I’ve noticed some frame drops happening at random that I haven’t encountered before.
In said game what will happen sometimes at random is this pattern of spike in the CPU usage for performance stats, with each spike being a FPS drop
At first I believed it could possible be a ping issue, but upon further investigation the ping is a stable average between 50 and 80 ms.
I then looked at the possibility of it being a memory leak of some sort but I do not believe that to be the case either as it stays within the same general usage.
I looked at my GPU in performance stats as well and any spikes don’t seem to line up there either, and the sent/receive areas are fine as well.
Looking at the microprofiler this is what the result looks like
Though not merely a programmer myself, try answering some of these questions:
Are you benchmarking the spikes while standing still?
Have you tested this on different devices?
Are there any scripts that go on forever, usually looped in short time periods?
Are you using any sort of way to try and optimize the game? (lod, chunk loading)
Are any free models used?
Is the FPS affected? (shift + F5)
Based off the background of your game screenshot, it appears to be detailed, so it could have to do with device and game optimization, but I can be wrong.
I dont have a second device to test it on, though the other testers have gotten the same results.
Im not entirely sure how to benchmark them whilst standing still
There are many scripts that do have loops in them but only because they have to. They are AI enemies that check the position of a player to see if theyre within a certain distance of them.
There is an optimization technique for loading certain map regions but its in very specific circumstances and doesnt apply here
There are a lot of free models, though none have scripts. I have tried to optimize a few
FPS is affected yes, a frame drop matches with the CPU spike
Just see if it drops by just standing still using Shift F5 for this.
Anyways for the AI, is there a script inside of each entity that checks player position or is it just one universal script that sends the information to them?
Do the free models have any excessive parts/unions in them?
Each AI has a script, I think some of the models have a bunch of unions, I do know some of them have 9000 tris and are spread out, some are partially Underground
For some reason, your FindFirstChild calls are causing the long spikes. Look at the ClientMover script and try to minimize your FindFirstChild calls. Though oddly those calls shouldn’t take 7ms to complete.
Edit: My best guess is that the FindFirstChild calls are not taking 7ms but the label was not ended for some reason.
Your best move from here is to start using debug.profilebegin(string) and debug.profileend() to figure out what part of the code is taking up all your cpu time.
(It will pop up as those labels in the microprofiler)