Sudden CPU usage spike

So. I have a platformer project. And about 30 minutes in, no matter what you do, CPU usage suddenly goes up. The project involves switching between a lot of scenes. But as it turns out, changing scenes is not an issue. Because, reportedly, one can just stand for 30 minutes in one level and get the bug as well. What I’ve found out so far:

  1. I ran a profiler. It remained consistent throughout the scenes with about 25% use of objects and 50% for events. I think the other 25% were events too. But that’s to be expected.
  2. During the lag spike, events suddenly go up to 100% usage and have a 203ms response time. The culprits are inconsistent since it shows the character’s FSM is to blame. But it didn’t seem to use a lot of CPU before that. Events running constantly and somehow adding up doesn’t seem to be an issue either.
  3. I managed to switch back to the Menu scene despite the lags. Cleared the storage. Launched the “first” scene once more without closing the preview. It worked again but with an occasional stutter. For a few scene changes. After which the lag and CPU usage came back.

So yeah. Bottom point is that regardless of whether you go through 60 scenes or stay at one scene for half an hour, it starts lagging. I can send the project if any GD devs are willing to look at it. On a side note, this thread mentions a similar issue:

Update: It seems like the amount of scenes is to blame after all. Specifically, the amount of individual scenes with their own objects. The number varies from 166 scene changes (if changing “unique” scenes rapidly) to 260 (if revisiting already visited scenes several times). So the issue is certainly the amount of scene changes. Which the new update doesn’t handle as well, apparently.

Hey, so I have 2+ years of experience with this issue in particular… First game had 50+ scenes, not only did this cause issues with the newer GD builds (opening 3 or more scenes one after the other brought the framerates down by like 75% for each new scene until it’s running at like 4 fps).

Two options here:

  1. Switch to an older build (5.0.130) works fine on a huge amount of scenes. Something about the builds after that (not sure exactly where the issue first appears), have some kind of issue where scenes aren’t properly cleared from memory or something.

  2. Just use a single scene and just cleverly split up different levels that way.

I wish I had known this earlier, obviously option two may not be viable for you because of the amount of work required to compile 60 scenes into 1.