Massive CPU spikes happening randomly in 5 second intervals

Hello everyone,

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

There are massive spikes that match the same as the CPU, specifically two of them

I’m not sure what’s causing this but any help is appreciated. Thank you in advance


is there anything with intervals of 5 seconds such as while wait(5) do, while task.wait(5) do, repeat task.wait(5) until, or repeat wait(5) until?

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?

Have you actually looked at microprofiler output to see what exactly is happening during those spikes?

1 Like

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

I’m not sure how to do that. How would I do that?

Enable the microprofiler, go to mode and turn on detailed. Pause the microprofiler and send a photo of it here.

Click the spike (or wait for a spike) and send a photo of the detailed spike

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.

Where would the clientmover script be? Or where could I find it?

You should be able to just search for it in the explorer

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)

Theres no script in the game called “clientmover”


Would I call those methods at spots where I suspect a lot of cpu time is being used?

The localscript might be getting inserted during runtime. Do the search while you are running the game.

Yeah your best bet is to just start using those labels for each function you suspect is taking a lot of cpu time until you find the root cause.

1 Like