Odd lag spikes, followed by dropoff

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By keke
:warning: Old Version Published before Godot 3 was released.

So I’ve been having these weird lag spikes where all of a sudden, the frame time will ramp up (not an instant jump - it takes a few frames to increase) and then drop off. Looking through the various functions being called, I can see that one of the _draw functions seems to be the culprit. I have a lot of code running in several draw functions (update() is being called every frame) so it might be that I just have some bad code in one of them.
However, I noticed something strange - after the spike drops, there is a single frame where no functions are being called - even non-gdscript stuff isn’t being run. This makes me think that maybe this is a weird engine problem? Or maybe godot is trying to catch up or something? It’s also worth noting that the spike in the picture isn’t the only spike - there are others that display the same ‘ramp up, drop off, single frame of nothing’ pattern. They are just much smaller. Is this an engine problem? If so, how do I fix it? If it’s a script problem then I’ll go and debug that.

TL;DR
I’m having multiple weird lag spikes, immediately followed by a single frame where no functions are being called.


Top: frame during latter half of spike - the frame time is decreasing. The little cutout shows how much frame time one of my _draw functions was consuming at the peak of the spike

Bottom: Single frame of nothing after the spike

I’m drawing a lot of lines, and I don’t have a graphics card. However, there isn’t an increase in the number of lines being drawn on those frames.