[Solved] Game performance drops after a while

I worked on optimizing the events in the settings section for a while and a little in the items. There were a lot of places there that needed a Trigger Once condition but honestly and it didn’t even reflect in the profiler at all.

I played through the game again and the intense lag started around the same place, actually right before the second boss this time.

The unaccounted for percentage of slowdown is still there and still above 50%. :confused:

I’m starting suspect the events that I wrote that it says are causing slower response times are multiplied in the profiler calculations because of the extremely slow speed the game is running at. I don’t really know if that’s possible but all the events that normally add 1 ms instead add 3 ms instead when the lag is occurring and it looks like this is roughly true for everything ( 0.1 ms now 0.3 ms, 0.5 ms now 1.5 ms, etc). The profiler in this screenshot says it ran for 313 frames but I let it go for at least 15 seconds real time or more. So I don’t know if I’m explaining this well but my theory is basically that the only reason it shows the events I wrote as causing 35-45% of the slowdown in the profiler is because the game is already intensely lagging so much so that it is multiplying it because it checks so less often.

Either way it looks to be an issue with the engine which I can do nothing about. I don’t think this was always happening so maybe it was introduced in a recent update? I’m going to try to rollback my version and see if that helps. I can’t go as far back as 5.0.130 which fixed this issue for Brainofcthulu and JohnyMangoes because my game relies on features that were released after that version but I’m hoping it will help somehow as it seems to be my only option at this point.

If anybody has any idea as to how to fix this I would really really appreciate it. Thank you to everyone who has tried to help so far.

Are you suggesting some kind of AI at work here? I don’t think GDevelop is that advanced/clever, unfortunately.

If you look at the profiler, it’s taking an average of 84ms for all events. As you pointed out, the biggest contributors are events which are not under any event grouping. Unless all events are under an event group, that’ll be the place I’d focus investigations.

If you care to share your project (zip up the project folder and put it on a file share, PM if you’re not keen on publicly linking it) then some of us on the forum could have a look and see if we can spot areas where it could be bottlenecking.

No, that’s not what I’m trying to say. I know I wasn’t communicating what I was trying to say well, to be honest I was almost confusing myself writing it. Either way my theories don’t matter though. I’m not a software developer working on this engine and I don’t know the ins and outs of it at all.

All events are under an event grouping. I don’t mean to be rude but I’ve been trying to fix this for 2-3 days now and of course something obvious like that was the first thing I checked. Anyway talking about my events completely ignores the fact that normally any scene with the same events in it runs completely smoothly. The performance only drops after a certain number of scene transitions every time, and if I “refresh” the scene by updating the preview the lag goes away entirely. I’m not giving up yet on fixing it though and I appreciate the help.

Update: I tried using the oldest Gdevelop version that still included the “Wait X Seconds” action. It did not help.

No worries. Most of these questions/suggestions are because we don’t know what you’ve done or what you are capable of. It’s not uncommon for new forum members to rush in with claims of a major bug in GDevelop, when they haven’t even done some basic checks.


It could be an accumulation effect. For example, if you create a scene with a few physics objects, it’ll run smoothly. But if you keep adding physics objects, eventually GDevelop will start lagging. Don’t get me wrong in that I’m implying that you’re not deleting object. I’m just trying to explain why something seems to work initially, and after a while it has issues. It could well be that GDevelop has an accumulation bug in scene changing (and just to check, you are changing scenes, and not pausing a scene and starting another?).

And as commented by @Silver-Streak a few months back :

So, it may just be a waiting game.

However, if you could recreate the issue with a basic, barebones project, then that could possibly help the devs pinpoint the problem.

Just to be clear, your screenshot seems to imply otherwise.
image

For clarification, only event groupings will show up as a heading, and your current groupings only account for 32 of the 84ms your events are taking. The top level events heading tracks a summary of all event groups as well as any ungrouped events.

Some events somewhere are taking up the other 50ms. If the event logic was getting multiplied somehow, the logic that is taking more time would show up in the group that is getting multiplied.

Unfortunately, even ignoring that, your item events alone are currently taking more than 1 frame of performance (16 ms is 1 frame of a 60 fps game). So that will still need to be optimized regardless.

Sadly, in this case I think this issue is wholly unrelated to what I was referring to in that post. JohnnyMangoes game, which I had been referring to, was a dramatic reduction in performance at all time and was (in theory) related to the WebGL support changes with the Electron/Chromium update. No one’s been able to reproduce that in a project the devs can investigate with, so while that may get resolved eventually if a proper example project is ever provided.

I’d be very interested to see if the events in question for Blackjester57’s issue can be narrowed down. The only thing I can guestimate is if there is an extensive usage of Wait events. Wait events are asynchronous, meaning they could take up tons of cpu cycles if the logic is undefined (or something like random intervals added to a wait command rather than predefined intervals/randoms stored in a variable).

1 Like

I understand that concept but I just can’t think of a way anything would have accumulated when the scene has just started. I’m definitely not pausing the scene and starting another, I’m just changing it to a new scene. Is there a way that it could be keeping the old scenes in memory or something? I’ve never used the pause or start scene events before.

That’s exactly how I thought it works, that’s why I’m so confused. Every scene in the game has the same external events connected to it and they are all in those event groups from the screenshot.

I have used a lot of wait events. Could this possible be the problem?? Why would it run normally until a certain amount of scene transitions? How could I replace the wait events with something more performant? I hope that is the issue somehow. I can’t see my project rn but I will look again later and be able to show my events that use wait actions.

Are they in conditional events?


Accumulation (see my previous post on the physics objects)?


How are you using them? Can you provide a screen snip of the events containing them?

Yes.

Accumulation of what exactly though? If the scene changes isn’t everything from the previous scene gone? If so how could anything be accumulating?

Yes.

Here I’m using the Wait action to set a limit on how often the player can attack. This is just one random instance of me using the Wait action though, I have used it a lot.


There are probably way more efficient ways of doing what I’m doing here I know. I never had a problem with it before now though…

The game normally has less than 4 ms of response time total though. If you scroll up farther you can see my screenshot with the exact same events and a total of 3.81 ms. That is the normal performance and the numbers only jump up when whatever glitch is causing the lag starts happening. Like I’m trying to say there are no performance issues whatsoever until the specific conditions happen that cause the lag (that being going through enough scene transitions)

Possibly those wait actions? What happens if the wait action hasn’t finished, but you change the scene? Is it removed from memory? Is it still running, and trying to work with objects/events that no longer exist?

How many player object are there? If only one, then you don’t need the repeat for each player,

If there are more than one, make it more efficient by doing the Player class check first, then the Player.Attacking check, and make the for each player object a subevent.

But here’s a potential bug - circled action 1 has the potential to trigger the circle condition 2, which in turn will toggle Player.Attacking to false, and the whole series of events are repeated. I’d suggest setting the value, rather than toggling it in this case :

I understand what you’re trying to achieve, but the logic isn’t quite there.

If you have quite a few different attacking states, I’d suggest looking at using a FSM. With this, you set the state of the player, and have events specifically for each state. Not-A-Vania (one of the GDevelop new project templates) implements such a system if you want an example project.

1 Like

I have no clue but that sounds like it could be the thing that causes my performance problem if thats the case. Although if it is thats just a glitch with the engine that I can’t do anything about. I guess I could try to use less Wait actions but that would just delay when the lag starts as I’ve already done somewhat. The game has 6 areas and the lag starts at the end of area 2. Never using a Wait action in my whole event sheet anywhere is probably unachievable for me at this point.

Potentially 2, that’s why I have it as a for each condition.

Also I’m not sure about the other stuff that your talking about but these events are working exactly as I intended.

So I can’t say for sure if Wait is causing your issue, and in most cases your only real other option would be to use timers instead.

However, I will call out that by using “for each”, and with your current setup, you are creating SIGNIFICANT amounts of KnightAttack and KnightAttack2 objects.
image

This action will occur EVERY FRAME until the conditions are false. you’re using a wait before setting the conditions false, with even 0.1 seconds of wait time you’re creating at least ~6+ KnightAttack/KnightAttack2 objects per action (and per player).

Additionally, just as MrMen mentioned, by using “NextAttackisAttack2 is false” in your top event, then toggling it with an action, then saying “NextAttack2 is true” in your next event, you’re rapidly toggling back and forth between these states. Meaning that even if you’re not seeing it, both subevents are happening.

I just doublechecked. It only creates one as intended because the condition about the attacking bool of player object.

That is intended.

Does anybody have any idea about this lag problem though? Is it because of wait events possibly?

To confirm, you checked with in the debugger once the lag kicked in?

Do you get the same issue if you compile the game for your machine and run it?

It’s intended that the game rapidly toggle between the two states and running both subevents?

I’d suggest on of two thing :

  1. Zip up your project and share it (PM if needed) so someone else can have a look at it. As it is, we’re guessing at the possible cause with only a sliver of any code/events. It could well be that what you think is efficient coding may not be. Otherwise :
  2. Refactor your events and use FSM. It’ll be a bit of work, but you’ll end up with events that are logically split and only run when needed.

It takes like 10 minutes of gameplay to recreate the lag spike, so no I didn’t specifically check that but the lag starts at the beginning of the scene before the player ever has a chance to attack for the first time. I checked when the game is not lagging, with its normal framerate.

I haven’t ever compiled this game yet. I guess I probably should check that because then I could technically continue development as normal but it would make testing pretty annoying. The reason I haven’t tried that yet is because the OP of this thread said his issue persisted whether it was in the preview or compiled.

I am willing to share the project with someone but I would much prefer screenshare on a discord call or something in that vein rather than sending my whole project to someone I don’t know. My game has hundreds of different pixel art frames drawn by me that no one has ever seen, a lot of them animated. I know that’s paranoid though. Also I don’t think any of my coding is necessarily efficient at all. This is my first project in this engine and I don’t have a background in CS of any kind. I expect a lot of it is not as efficient as it could be but the game usually runs with a 2-4 ms response time, other than this unexplainable and extreme anomaly.

I have no clue what FSM is.

Update: The issue persists in the game if its compiled.

FSM is Finite State Machine. You determine the various states a player can be; like idle, running, jumping, falling, landing, attacking etc. There would be an event to check for each state, and then that would have a set of subevents which determine what to do during with keypresses and any other actions that can occur in that state. So along the lines of :

State is ïdle"
 - keypress is left, set State to "running", direction = "left"
 - keypress is right, set State to "running", direction = "right"
 - keypress is space, set State to jump

State is jump
 ... actions for jumping ...

etc

Well the player has only two states in my game, moving or standing still, and those are really only an animation change. No matter what the player is doing all key presses do the exact same thing. So I don’t understand how that would help me at all, like I said those events work exactly as intended.

Is there anybody who would be willing to get on a call with me and check out my project? I would be willing to work with anyone’s schedule time wise. I know its asking a lot but I have put months of work into the project and it was closer to being finished than just getting started. It means a lot to me so I don’t want to give up.