GMS 2.3+ FPS drops suddenly

enriqe

Member
Hi guys.
I'm writing my game in GMS2 and I have this problem. If anyone can point me in right direction, would be much appreciated.

I have room of size 6000 x 3000 and on create event I place 6000 instances of my Tree object there.
It's just a forest country. Grass made of tiles and trees as instances.

I also have some 3 characters there but they do nothing for now.
They can move around after I select them and click new place to go to.

But my problem is - I'm experiencing strange FPS drop to the half after a while.
Exactly to the half and suddenly - strange.
I'm not even touching my game after start. Nothing. FPS just drops after few seconds.
Please if you can take a look at this - I recorded profiler on video. If you have any idea.... please tell me.

I test it on my Android mobile Huawei P10.


Thank you very much.
 
Last edited:

enriqe

Member
Honestly I think to get more info we need to know what the trees are doing, because 6000 is A LOT of instances
They do nothing.
After creation they have set their depth = -y but they have no code on them.

When a Character is moving, it uses mp_potential_step to avoid those trees, but as shown in video - I'm not moving my characters at all.

Thanks.
 

Moon Goat

Member
I would have to take a look at the project to see what was happening.

But just for the record, if the trees are just decorations, then you can just place their sprites in the game as assets instead of objects.

Objects tend to use up a lot of memory just with their event executions without any code.

If you do eventually need to have characters interact with the trees or something, you can do something like this to optimize performance:

You put all the objects you have a lot of on an exclusive layer, call it layer_deactivate.

Then you would call
instance_deactivate_layer(layer_deactivate) to deactivate all those instances at the start of the room without affecting other essential objects.
You would then activate the trees and other plentiful instances as you need them with
instance_activate_region();

You can even have the game automatically optimize performance with something like this:

GML:
if( fps_real < room_speed + 100 )
{

instance_deactivate_layer(layer_deactivate);

var vx = camera_get_view_x(view_camera[0]);
var vy = camera_get_view_y(view_camera[0]);
var vw = camera_get_view_width(view_camera[0]);
var vh = camera_get_view_height(view_camera[0]);

instance_activate_region(vx, vy, vw, vh, true );

}
 
Last edited:
They do nothing.
After creation they have set their depth = -y but they have no code on them.
when you do this, GM will create a new layer for each y, which can add up to a lot of overhead. That's not really a good practice, especially on mobile. Maybe go back to the *ahem* drawing board, and re-think your draw logic with that in mind. But the drop is suspicious, I admit.
 
Yes I do believe it is suspicious, my thought process is FPS drop and that there are 600 instances so I put two and two together BUT the fact that you are not doing anything and FPS just drops, I agree is very suspicious. Maybe run the game a few times and see if the FPS drops at the exact same time
 

enriqe

Member
Hi guys.
Yes it's very suspicious especially if FPS drops exactly 50%. I think it can be hardware issue of the mobile phone trying to save energy or something like that. I switched off the settings of "auto energy management" in the mobile but did not help. I should try different mobile / brand.

@Moon Goat I used objects instead of sprites while I wanted my characters (there will be more of them, up to 10-15) to use collisions and mp_potential_step and also depth-checking when moving through the forest so it looks realistic. And while some of those characters are off the current camera view doing their job (like cutting the trees or just moving around) I thought I could not to deactivate trees which are off the camera view while those objects would be switched off and paused. Anyway thank you very much for good tips and code.

@Slow Fingers you really surprised me with the info about layer for each Y. Wow thank you. But as I wrote in paragraph above, I have no idea how to accomplish this in some other way.

@Mr.Celsuis no it's not at the exact time. Exactly how you wrote - I'm doing nothing in my game. If the game runs at 80 FPS for some time, it should mean I don't have performance issues, it probably means..... there is something else in the way....
 
@Slow Fingers you really surprised me with the info about layer for each Y. Wow thank you. But as I wrote in paragraph above, I have no idea how to accomplish this in some other way.
Maybe sort them by y, and then draw them in ascending order, but on the same layer, and dont mess around with depth at all.

When a Character is moving, it uses mp_potential_stepto avoid those trees, but as shown in video - I'm not moving my characters at all.
This gets me thinking, how are you checking for your motion planning? In the event you try to compute 6000 paths at once, one just MIGHT expect an ever slight fps drop...
 

Padouk

Member
That sounds like Power Saving issue. 80fps is a bit of a high target for mobile.
I use 45, but I don't want to start a war on numbers.

I'd advice you to look at your Device settings to disable Power saving when plugged (for development purposes) or try to target a lower fps

--
Everything else about number of instances all this might be true.. but what you are experiencing really seems related to this configuration. which kicks in after a short 15ish sec idle (no touch) on some devices.

if you don't know what I'm talking about have a read here: https://developer.akamai.com/blog/2...s-battery-saver-degrade-mobile-web-experience
 
Yes that is why I asked if it happened at the same time, to check if something was causing it that you coded without realizing it would do that, this does not mean that that could still be possible just unlikely now that we know this.
 
Everything else about number of instances all this might be true.. but what you are experiencing really seems related to this configuration. which kicks in after a short 15ish sec idle (no touch) on some devices.
I am really no expert in mobile dev, but doesn't this triggers some sort of async system event? that would make it quite easy to debug if this is the case...
 

enriqe

Member
Hi all.
So please take a look at this.
I added one Alarm into my game and this is the code in that Alarm:

GML:
var runTime = round(current_time/1000);

show_debug_message(string(runTime) + "sec. running at "+string(room_speed) + " FPS room speed");

alarm_set(10, room_speed);
Is this video an evidence mobile cuts CPU clock for my game?
Or is it useless while alarms depend on real FPS?

 
Last edited:

Padouk

Member
Is this video an evidence mobile cuts CPU clock for my game?
Or is it useless while alarms depend on real FPS?
Ahoy mate.
The throttle you are facing is part of the mobile experience to be expected by your end user. Steer into it by reducing your Game Speed (game fps) to something in line with the throtteled speed... Like 45fps

About your "auto energy management". It's a good start but even with the latest android claims, the power management is not unified amongs manufacturer yet.
You might need to look into specific features for your's
--

I'm a bit rusty on Huawei devices but maybe you could looking for the Ignore Optimization configuration. (http://nine-faq.9folders.com/articl...ff-battery-optimization-on-the-huawei-devices)
see if disabling that one stabilize your fps to 80 in debug mode the way you want
 

enriqe

Member
Thank you @Padouk - but it's basically what I did on my phone before.

Guys thanks for pointing out that having every tree in different depth makes it on different layer.
This is really a huge performance hit. After I disabled depth = -y, my FPS went to 200!

Unfortunatelly, after a while I still have that silly FPS drop down to 90, but at least it's still nice FPS.

Looks like there is no way to guarantee this drop will not happen on any mobile of any other player.
Even if I can stabilise it on my phone, it can happen to anyone. Strange I haven't heard about this in tutorials/forums.
It means I have to try some different "depth" strategies (thanks @Slow Fingers ).

Here I just want to show you what I want to achieve:
(this is still done with my old "depth approach", FPS is irrelevant here while it was recorded on my PC)

 
Last edited:
Top