Would this be a "bottleneck" in the code or what?

Hello. can someone clear my doubt? How can I find “bottlenecks” in the game?

I will explain the situation first. A few days ago I refactored all my code (timers, variables, etc.) which improved a lot and also made the code more organized and cleaner. However, it’s been a while since I noticed the delay to load when pressing the “preview” button. It takes about 20 seconds to start loading the game. So, other than that, the game loads very fast and flows perfectly.

In debug mode, from gdevelop, there is no problem because the problems that there were I fixed a long time ago. In developer mode, the same thing, it doesn’t give me any error or warning.

The delay I’m referring to is this:

Is there any way to find out what might be going on? What could be causing this?

NOTE: There is an external event that if I disable it, the time drops to about 5 seconds. This event has calculations, but these calculations are only performed if the player is colliding with the enemy, which makes no sense. But I have to say it here.

This is very peculiar. I think it may be worth to disable or deactivate one thing at a time until you figure out what the large issues are. In your post script you mention that an external event, when disabled, drops your wait to 5 seconds sounds substantial. I would obviously look more into that specific event group as well as others and see what is being used. Since your game is opening to a start screen, are those hit detections being checked? What external events are present and attached to the start menu? Since it opens to that, you could even have task manager up and see if when you attempt to run the game, if your ram usage spikes. Please let us know your finding as you go. You may discover something very useful to others.

Hello, Opening the task manager, memory and CPU are absolutely inert, that is, there is no evidence of memory or CPU overflow.

As for the external event, it is not present in the menu, only when the game actually starts. That is, when giving a preview, the game starts in the menu, which is just a separate scene, and only when clicking on new game does that external event start. And even for this external event to work, there must be some kind of enemy in the scene, otherwise it shouldn’t work.

PS: This 20-second delay happens on Linux, on Windows, it takes almost 1 minute :thinking: :grimacing:

That is very strange then. Do you have any other projects that act this same way? If you had a new project with nothing on it, how does that run? That could at least rule out that your system is having an issue with Gdevelop and from there you could start to figure out if its something within your project that is acting up.

Last thing i can suggest is making sure all your files (images, music, etc.) Are within your actual project folder. If they’re not, the game has to create all those files and compile them before making a preview. That could be the case.

As for new projects, they are normal, it doesn’t even last 3 seconds for preview. This project of mine in question, if it’s a game I’ve been developing for about 1 year or so, I had to refactor a few times to change the IDE itself, and I’m fine with that. But the fact is, I need a direction to know where to start fixing the problems if it’s really my code. But without a debug of what might be going on and I have no idea.

As for the files in general, I keep them organized from the beginning of the project, and as you can see, it’s in the project folder:

At this point it probably is just your code like you said. I guess you have to go through each event sheet and figure out where something is either going wrong or interacting in a way that would slow down performance. You could try pulling some of your event sheets into a new project one by one and see if any of them specifically have an effect.

I did the test, put the same code that the problem happens in a new project, and your preview is instant!
I did the test placing the same objects and the same thing happens, the preview is instantaneous!

I’m starting to think it might be some function that was updated and that I’m still in the old one… I’ll do a good search! I will post updates on the matter here. However, thanks for the help.

1 Like

Of course! Let us know your findings.

As I said, just one event sheet made the game take a while to preview. Well, I found the problem. All places where there is “randominRange” make the game take a while to start the preview. If I disable it, it goes back to normal.

I did some tests, and in all of them the preview takes a long time to load:

1 - I put the problem line inside the scene
2 - I put the problem line in another event sheet
3 - I disabled everything in the game and left only the line that gives the problem

The code in the image is only activated if the Hero collides (hits) the enemy.


Is there anything new about this issue?

I have a similar problem I guess, for a long time.
Clicking on the preview button it can take about 10 min to launch the preview. The loading bar itself doesn’t take long.

First I thought it was because of my project that have a lot of external events, and calculation. So I accepted it and worked this way so far.

When I launch the preview, just like in @willianholtz example, my game starts on a scene with almost no events. So in this starting scene there’s no complicated calculation. Only a link to another scene if one key is released.

Other smaller projects launch quickly their previews, so I did thought it was because of my big project.

But reading this post, I see someone had a similar problem, and the conclusion was the RandominRange function slowing down the preview launching… I do use many RandominRange function.

So, is there anything new about this issue?

I’m currently using Gdevelop 5.0.139
But I have this problem for at least 5 months

As @CTXB said above, best way to debug this would be to make a copy of your project (so you’re not messing with the original in case you stuff something up), then go through and disable/delete parts of your code/game, testing to see if/when the preview loading goes back to normal.

I’d recommend disabling blocks of code one-by-one, then once the preview loads normally, re-enable the last block you just disabled, then go through that and disable each part one-by-one until you find the culprit.

1 Like

Thank you for your reply.

Yes I think I will have to go through that.
But it won’t be easy.
First of all because my project is full of external events linked together, so I cannot just disabled one part easily.
Then, it’s not a usual bug. Because if I launch an empty scene in this project, the problem is the same (!).
But I guess yes, to do what you said seem to be my best option.

Maybe I’ll try to test each external event alone.

I’m curious to know what does the preview when launching… Before even reading the starting scene.
I guess it assemble all scenes and external events into one single code…?
I’m curious about it cause the issue doesn’t seem to be in the actual scene events.

Is it unadvisable to have nested external events…?

I solved my problem by refactoring everything… But everything! A lot of things have changed in the last year, and as my project is over a year old, I was forced to refactor. However, I can say one thing:
Linux version which is the default I use, loading is super fast, now when I load the same project on Windows, it takes about 30 seconds… And I can’t understand why.

edit: What helped me, at least on linux, is that many old variables were like String, and used numbers, I don’t know if that had something to do with it, but after I changed that and other behaviors, it got better!

1 Like

Hi, thanks a lot for your answer.

This might be a good hint… Many times in my project I use a variable as a string and as a number.
I took the habit (bad I guess) to directly write VariableString(x) instead of ToString(Variable(x)) when i want to get the string of variable(x) that is a number.
I thought it was equivalent.
The other way around, I usually use Variable(text) to get the number of a string variable, instead of using ToNumber(VariableString(text)).

Can someone confirm me it’s a bad habit…? So far I thought it was equivalent.

So in the end you don’t think the problem was the RandominRange function…?

First I had doubts about my nested External Events, but in the end I have more the feeling now that some code inside my External Events is slow, and since it’s an external event, repeated many times, it slows down the whole thing.

What I can actually say is that RandoninRange is not the cause of failures in my project anymore, it was because many variables were “wrong”. I had a delay of more or less 1 min depending on the situation. Another thing that made my project more fluid was the fact that I passed all possible animations to Tiled (yes I use it to make my game rooms and everything else) as well as background and the rest of things. And these files are no longer in GD, I believe it has improved a lot.

1 Like

Thanks a lot. I’ll give more details if ever I find something new.

1 Like

All good! :smile: I haven’t closed this topic yet because in fact it hasn’t 100% solved the problem! Feel free to use the same for you to post updates and tips on improvements.

1 Like